<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveRecord::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveRecord::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activerecord/lib/active_record/base_rb.html">
                vendor/rails/activerecord/lib/active_record/base.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Active Record objects don&#8216;t specify their <a
href="Base.html#M001448">attributes</a> directly, but rather infer them
from the table definition with which they&#8216;re linked. Adding,
removing, and changing <a href="Base.html#M001448">attributes</a> and their
type is done directly in the database. Any change is instantly reflected in
the Active Record objects. The mapping that binds a given Active Record
class to a certain database table will happen automatically in most common
cases, but can be overwritten for the uncommon ones.
</p>
<p>
See the mapping rules in <a href="Base.html#M001396">table_name</a> and the
full example in <a href="../../files/README.html">files/README.html</a> for
more insight.
</p>
<h2>Creation</h2>
<p>
Active Records accept constructor parameters either in a <a
href="Base.html#M001457">hash</a> or as a block. The <a
href="Base.html#M001457">hash</a> method is especially useful when
you&#8216;re receiving the data from somewhere else, like an HTTP request.
It works like this:
</p>
<pre>
  user = User.new(:name =&gt; &quot;David&quot;, :occupation =&gt; &quot;Code Artist&quot;)
  user.name # =&gt; &quot;David&quot;
</pre>
<p>
You can also use block initialization:
</p>
<pre>
  user = User.new do |u|
    u.name = &quot;David&quot;
    u.occupation = &quot;Code Artist&quot;
  end
</pre>
<p>
And of course you can just <a href="Base.html#M001379">create</a> a bare
object and specify the <a href="Base.html#M001448">attributes</a> after the
fact:
</p>
<pre>
  user = User.new
  user.name = &quot;David&quot;
  user.occupation = &quot;Code Artist&quot;
</pre>
<h2>Conditions</h2>
<p>
Conditions can either be specified as a string, array, or <a
href="Base.html#M001457">hash</a> representing the WHERE-part of an SQL
statement. The array form is to be used when the condition input is tainted
and requires sanitization. The string form can be used for statements that
don&#8216;t involve tainted data. The <a href="Base.html#M001457">hash</a>
form works much like the array form, except only equality and range is
possible. Examples:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    def self.authenticate_unsafely(user_name, password)
      find(:first, :conditions =&gt; &quot;user_name = '#{user_name}' AND password = '#{password}'&quot;)
    end

    def self.authenticate_safely(user_name, password)
      find(:first, :conditions =&gt; [ &quot;user_name = ? AND password = ?&quot;, user_name, password ])
    end

    def self.authenticate_safely_simply(user_name, password)
      find(:first, :conditions =&gt; { :user_name =&gt; user_name, :password =&gt; password })
    end
  end
</pre>
<p>
The <tt>authenticate_unsafely</tt> method inserts the parameters directly
into the query and is thus susceptible to SQL-injection attacks if the
<tt>user_name</tt> and <tt>password</tt> parameters come directly from an
HTTP request. The <tt>authenticate_safely</tt> and
<tt>authenticate_safely_simply</tt> both will sanitize the
<tt>user_name</tt> and <tt>password</tt> before inserting them in the
query, which will ensure that an attacker can&#8216;t escape the query and
fake the login (or worse).
</p>
<p>
When using multiple parameters in the conditions, it can easily become hard
to read exactly what the fourth or fifth question mark is supposed to
represent. In those cases, you can resort to named bind variables instead.
That&#8216;s done by replacing the question marks with symbols and
supplying a <a href="Base.html#M001457">hash</a> with values for the
matching symbol keys:
</p>
<pre>
  Company.find(:first, :conditions =&gt; [
    &quot;id = :id AND name = :name AND division = :division AND created_at &gt; :accounting_date&quot;,
    { :id =&gt; 3, :name =&gt; &quot;37signals&quot;, :division =&gt; &quot;First&quot;, :accounting_date =&gt; '2005-01-01' }
  ])
</pre>
<p>
Similarly, a simple <a href="Base.html#M001457">hash</a> without a
statement will generate conditions based on equality with the SQL AND
operator. For instance:
</p>
<pre>
  Student.find(:all, :conditions =&gt; { :first_name =&gt; &quot;Harvey&quot;, :status =&gt; 1 })
  Student.find(:all, :conditions =&gt; params[:student])
</pre>
<p>
A range may be used in the <a href="Base.html#M001457">hash</a> to use the
SQL BETWEEN operator:
</p>
<pre>
  Student.find(:all, :conditions =&gt; { :grade =&gt; 9..12 })
</pre>
<h2>Overwriting default accessors</h2>
<p>
All column values are automatically available through basic accessors on
the Active Record object, but sometimes you want to specialize this
behavior. This can be done by overwriting the default accessors (using the
same name as the attribute) and calling read_attribute(attr_name) and
write_attribute(attr_name, value) to actually change things. Example:
</p>
<pre>
  class Song &lt; ActiveRecord::Base
    # Uses an integer of seconds to hold the length of the song

    def length=(minutes)
      write_attribute(:length, minutes * 60)
    end

    def length
      read_attribute(:length) / 60
    end
  end
</pre>
<p>
You can alternatively use self[:attribute]=(value) and self[:attribute]
instead of write_attribute(:attribute, value) and
read_attribute(:attribute) as a shorter form.
</p>
<h2>Attribute query methods</h2>
<p>
In addition to the basic accessors, query methods are also automatically
available on the Active Record object. Query methods allow you to test
whether an attribute value is present.
</p>
<p>
For example, an Active Record User with the <tt>name</tt> attribute has a
<tt>name?</tt> method that you can call to determine whether the user has a
name:
</p>
<pre>
  user = User.new(:name =&gt; &quot;David&quot;)
  user.name? # =&gt; true

  anonymous = User.new(:name =&gt; &quot;&quot;)
  anonymous.name? # =&gt; false
</pre>
<h2>Accessing <a href="Base.html#M001448">attributes</a> before they have been typecasted</h2>
<p>
Sometimes you want to be able to read the raw attribute data without having
the column-determined typecast run its course first. That can be done by
using the &lt;attribute&gt;_before_type_cast accessors that all <a
href="Base.html#M001448">attributes</a> have. For example, if your Account
model has a balance attribute, you can call
account.balance_before_type_cast or account.id_before_type_cast.
</p>
<p>
This is especially useful in validation situations where the user might
supply a string for an integer field and you want to display the original
string back in an error message. Accessing the attribute normally would
typecast the string to 0, which isn&#8216;t what you want.
</p>
<h2>Dynamic attribute-based finders</h2>
<p>
Dynamic attribute-based finders are a cleaner way of getting (and/or
creating) objects by simple queries without turning to SQL. They work by
appending the name of an attribute to <tt>find_by_</tt> or
<tt>find_all_by_</tt>, so you get finders like Person.find_by_user_name,
Person.find_all_by_last_name, Payment.find_by_transaction_id. So instead of
writing <tt>Person.find(:first, :conditions =&gt; [&quot;user_name =
?&quot;, user_name])</tt>, you just do
<tt>Person.find_by_user_name(user_name)</tt>. And instead of writing
<tt>Person.find(:all, :conditions =&gt; [&quot;last_name = ?&quot;,
last_name])</tt>, you just do
<tt>Person.find_all_by_last_name(last_name)</tt>.
</p>
<p>
It&#8216;s also possible to use multiple <a
href="Base.html#M001448">attributes</a> in the same <a
href="Base.html#M001376">find</a> by separating them with
&quot;<em>and</em>&quot;, so you get finders like
<tt>Person.find_by_user_name_and_password</tt> or even
<tt>Payment.find_by_purchaser_and_state_and_country</tt>. So instead of
writing <tt>Person.find(:first, :conditions =&gt; [&quot;user_name = ? AND
password = ?&quot;, user_name, password])</tt>, you just do
<tt>Person.find_by_user_name_and_password(user_name, password)</tt>.
</p>
<p>
It&#8216;s even possible to use all the additional parameters to <a
href="Base.html#M001376">find</a>. For example, the full interface for
Payment.find_all_by_amount is actually Payment.find_all_by_amount(amount,
options). And the full interface to Person.find_by_user_name is actually
Person.find_by_user_name(user_name, options). So you could call
<tt>Payment.find_all_by_amount(50, :order =&gt;
&quot;created_on&quot;)</tt>.
</p>
<p>
The same dynamic finder style can be used to <a
href="Base.html#M001379">create</a> the object if it doesn&#8216;t already
exist. This dynamic finder is called with <tt>find_or_create_by_</tt> and
will return the object if it already exists and otherwise creates it, then
returns it. Example:
</p>
<pre>
  # No 'Summer' tag exists
  Tag.find_or_create_by_name(&quot;Summer&quot;) # equal to Tag.create(:name =&gt; &quot;Summer&quot;)

  # Now the 'Summer' tag does exist
  Tag.find_or_create_by_name(&quot;Summer&quot;) # equal to Tag.find_by_name(&quot;Summer&quot;)
</pre>
<p>
Use the <tt>find_or_initialize_by_</tt> finder if you want to return a <a
href="Base.html#M001425">new</a> record without saving it first. Example:
</p>
<pre>
  # No 'Winter' tag exists
  winter = Tag.find_or_initialize_by_name(&quot;Winter&quot;)
  winter.new_record? # true
</pre>
<p>
To <a href="Base.html#M001376">find</a> by a subset of the <a
href="Base.html#M001448">attributes</a> to be used for instantiating a <a
href="Base.html#M001425">new</a> object, pass a <a
href="Base.html#M001457">hash</a> instead of a list of parameters. For
example:
</p>
<pre>
  Tag.find_or_create_by_name(:name =&gt; &quot;rails&quot;, :creator =&gt; current_user)
</pre>
<p>
That will either <a href="Base.html#M001376">find</a> an existing tag named
&quot;rails&quot;, or <a href="Base.html#M001379">create</a> a <a
href="Base.html#M001425">new</a> one while setting the user that created
it.
</p>
<h2>Saving arrays, hashes, and other non-mappable objects in text <a href="Base.html#M001404">columns</a></h2>
<p>
Active Record can <a href="Base.html#M001394">serialize</a> any object in
text <a href="Base.html#M001404">columns</a> using YAML. To do so, you must
specify this with a call to the class method <tt><a
href="Base.html#M001394">serialize</a></tt>. This makes it possible to
store arrays, hashes, and other non-mappable objects without doing any
additional work. Example:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    serialize :preferences
  end

  user = User.create(:preferences =&gt; { &quot;background&quot; =&gt; &quot;black&quot;, &quot;display&quot; =&gt; large })
  User.find(user.id).preferences # =&gt; { &quot;background&quot; =&gt; &quot;black&quot;, &quot;display&quot; =&gt; large }
</pre>
<p>
You can also specify a class option as the second parameter that&#8216;ll
raise an exception if a serialized object is retrieved as a descendent of a
class not in the hierarchy. Example:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    serialize :preferences, Hash
  end

  user = User.create(:preferences =&gt; %w( one two three ))
  User.find(user.id).preferences    # raises SerializationTypeMismatch
</pre>
<h2>Single table inheritance</h2>
<p>
Active Record allows inheritance by storing the name of the class in a
column that by default is named &quot;type&quot; (can be changed by
overwriting <tt><a
href="Base.html#M001398">Base.inheritance_column</a></tt>). This means that
an inheritance looking like this:
</p>
<pre>
  class Company &lt; ActiveRecord::Base; end
  class Firm &lt; Company; end
  class Client &lt; Company; end
  class PriorityClient &lt; Client; end
</pre>
<p>
When you do Firm.create(:name =&gt; &quot;37signals&quot;), this record
will be saved in the companies table with type = &quot;Firm&quot;. You can
then fetch this row again using Company.find(:first, &quot;name =
&#8216;37signals&#8217;&quot;) and it will return a Firm object.
</p>
<p>
If you don&#8216;t have a type column defined in your table, single-table
inheritance won&#8216;t be triggered. In that case, it&#8216;ll work just
like normal subclasses with no special magic for differentiating between
them or reloading the right type with <a href="Base.html#M001376">find</a>.
</p>
<p>
Note, all the <a href="Base.html#M001448">attributes</a> for all the cases
are kept in the same table. Read more: <a
href="http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html">www.martinfowler.com/eaaCatalog/singleTableInheritance.html</a>
</p>
<h2>Connection to multiple databases in different models</h2>
<p>
Connections are usually created through <a
href="Base.html#M001467">ActiveRecord::Base.establish_connection</a> and
retrieved by <a href="Base.html#M001463">ActiveRecord::Base.connection</a>.
All classes inheriting from <a href="Base.html">ActiveRecord::Base</a> will
use this <a href="Base.html#M001463">connection</a>. But you can also set a
class-specific <a href="Base.html#M001463">connection</a>. For example, if
Course is an <a href="Base.html">ActiveRecord::Base</a>, but resides in a
different database, you can just say Course.establish_connection and Course
*and all its subclasses* will use this <a
href="Base.html#M001463">connection</a> instead.
</p>
<p>
This feature is implemented by keeping a <a
href="Base.html#M001463">connection</a> pool in <a
href="Base.html">ActiveRecord::Base</a> that is a Hash indexed by the
class. If a <a href="Base.html#M001463">connection</a> is requested, the
retrieve_connection method will go up the class-hierarchy until a <a
href="Base.html#M001463">connection</a> is found in the <a
href="Base.html#M001463">connection</a> pool.
</p>
<h2>Exceptions</h2>
<ul>
<li><tt><a href="ActiveRecordError.html">ActiveRecordError</a></tt> &#8212;
generic error class and superclass of all other errors raised by Active
Record

</li>
<li><tt><a href="AdapterNotSpecified.html">AdapterNotSpecified</a></tt> &#8212;
the configuration <a href="Base.html#M001457">hash</a> used in <tt><a
href="Base.html#M001467">establish_connection</a></tt> didn&#8216;t include
an <tt>:adapter</tt> key.

</li>
<li><tt><a href="AdapterNotFound.html">AdapterNotFound</a></tt> &#8212; the
<tt>:adapter</tt> key used in <tt><a
href="Base.html#M001467">establish_connection</a></tt> specified a
non-existent adapter (or a bad spelling of an existing one).

</li>
<li><tt><a href="AssociationTypeMismatch.html">AssociationTypeMismatch</a></tt>
&#8212; the object assigned to the association wasn&#8216;t of the type
specified in the association definition.

</li>
<li><tt><a
href="SerializationTypeMismatch.html">SerializationTypeMismatch</a></tt>
&#8212; the serialized object wasn&#8216;t of the class specified as the
second parameter.

</li>
<li><tt><a
href="ConnectionNotEstablished.html">ConnectionNotEstablished</a></tt>
&#8212; no <a href="Base.html#M001463">connection</a> has been established.
Use <tt><a href="Base.html#M001467">establish_connection</a></tt> before
querying.

</li>
<li><tt><a href="RecordNotFound.html">RecordNotFound</a></tt> &#8212; no record
responded to the <a href="Base.html#M001376">find</a>* method. Either the
row with the given ID doesn&#8216;t exist or the row didn&#8216;t meet the
additional restrictions.

</li>
<li><tt><a href="StatementInvalid.html">StatementInvalid</a></tt> &#8212; the
database server rejected the SQL statement. The precise error is added in
the message. Either the record with the given ID doesn&#8216;t exist or the
record didn&#8216;t meet the additional restrictions.

</li>
<li><tt>MultiparameterAssignmentErrors</tt> &#8212; collection of errors that
occurred during a mass assignment using the +<a
href="Base.html#M001447">attributes=</a>+ method. The <tt>errors</tt>
property of this exception contains an array of
<tt>AttributeAssignmentError</tt> objects that should be inspected to
determine which <a href="Base.html#M001448">attributes</a> triggered the
errors.

</li>
<li><tt>AttributeAssignmentError</tt> &#8212; an error occurred while doing a
mass assignment through the +<a href="Base.html#M001447">attributes=</a>+
method. You can <a href="Base.html#M001410">inspect</a> the
<tt>attribute</tt> property of the exception object to determine which
attribute triggered the error.

</li>
</ul>
<p>
<b>Note</b>: The <a href="Base.html#M001448">attributes</a> listed are
class-level <a href="Base.html#M001448">attributes</a> (accessible from
both the class and instance level). So it&#8216;s possible to assign a
logger to the class through Base.logger= which will then be used by all
instances in the current object space.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001455">==</a>&nbsp;&nbsp;
      <a href="#M001413">===</a>&nbsp;&nbsp;
      <a href="#M001445">[]</a>&nbsp;&nbsp;
      <a href="#M001446">[]=</a>&nbsp;&nbsp;
      <a href="#M001415">abstract_class?</a>&nbsp;&nbsp;
      <a href="#M001391">attr_accessible</a>&nbsp;&nbsp;
      <a href="#M001390">attr_protected</a>&nbsp;&nbsp;
      <a href="#M001392">attr_readonly</a>&nbsp;&nbsp;
      <a href="#M001450">attribute_for_inspect</a>&nbsp;&nbsp;
      <a href="#M001453">attribute_names</a>&nbsp;&nbsp;
      <a href="#M001451">attribute_present?</a>&nbsp;&nbsp;
      <a href="#M001448">attributes</a>&nbsp;&nbsp;
      <a href="#M001447">attributes=</a>&nbsp;&nbsp;
      <a href="#M001449">attributes_before_type_cast</a>&nbsp;&nbsp;
      <a href="#M001414">base_class</a>&nbsp;&nbsp;
      <a href="#M001434">becomes</a>&nbsp;&nbsp;
      <a href="#M001411">benchmark</a>&nbsp;&nbsp;
      <a href="#M001419">class_of_active_record_descendant</a>&nbsp;&nbsp;
      <a href="#M001464">clear_active_connections!</a>&nbsp;&nbsp;
      <a href="#M001465">clear_reloadable_connections!</a>&nbsp;&nbsp;
      <a href="#M001433">clone</a>&nbsp;&nbsp;
      <a href="#M001454">column_for_attribute</a>&nbsp;&nbsp;
      <a href="#M001406">column_names</a>&nbsp;&nbsp;
      <a href="#M001404">columns</a>&nbsp;&nbsp;
      <a href="#M001405">columns_hash</a>&nbsp;&nbsp;
      <a href="#M001418">compute_type</a>&nbsp;&nbsp;
      <a href="#M001468">connected?</a>&nbsp;&nbsp;
      <a href="#M001463">connection</a>&nbsp;&nbsp;
      <a href="#M001466">connection</a>&nbsp;&nbsp;
      <a href="#M001407">content_columns</a>&nbsp;&nbsp;
      <a href="#M001386">count_by_sql</a>&nbsp;&nbsp;
      <a href="#M001379">create</a>&nbsp;&nbsp;
      <a href="#M001440">decrement</a>&nbsp;&nbsp;
      <a href="#M001441">decrement!</a>&nbsp;&nbsp;
      <a href="#M001389">decrement_counter</a>&nbsp;&nbsp;
      <a href="#M001381">delete</a>&nbsp;&nbsp;
      <a href="#M001385">delete_all</a>&nbsp;&nbsp;
      <a href="#M001409">descends_from_active_record?</a>&nbsp;&nbsp;
      <a href="#M001432">destroy</a>&nbsp;&nbsp;
      <a href="#M001382">destroy</a>&nbsp;&nbsp;
      <a href="#M001384">destroy_all</a>&nbsp;&nbsp;
      <a href="#M001456">eql?</a>&nbsp;&nbsp;
      <a href="#M001467">establish_connection</a>&nbsp;&nbsp;
      <a href="#M001378">exists?</a>&nbsp;&nbsp;
      <a href="#M001376">find</a>&nbsp;&nbsp;
      <a href="#M001377">find_by_sql</a>&nbsp;&nbsp;
      <a href="#M001458">freeze</a>&nbsp;&nbsp;
      <a href="#M001459">frozen?</a>&nbsp;&nbsp;
      <a href="#M001452">has_attribute?</a>&nbsp;&nbsp;
      <a href="#M001457">hash</a>&nbsp;&nbsp;
      <a href="#M001426">id</a>&nbsp;&nbsp;
      <a href="#M001428">id=</a>&nbsp;&nbsp;
      <a href="#M001438">increment</a>&nbsp;&nbsp;
      <a href="#M001439">increment!</a>&nbsp;&nbsp;
      <a href="#M001388">increment_counter</a>&nbsp;&nbsp;
      <a href="#M001398">inheritance_column</a>&nbsp;&nbsp;
      <a href="#M001410">inspect</a>&nbsp;&nbsp;
      <a href="#M001462">inspect</a>&nbsp;&nbsp;
      <a href="#M001425">new</a>&nbsp;&nbsp;
      <a href="#M001429">new_record?</a>&nbsp;&nbsp;
      <a href="#M001397">primary_key</a>&nbsp;&nbsp;
      <a href="#M001461">readonly!</a>&nbsp;&nbsp;
      <a href="#M001460">readonly?</a>&nbsp;&nbsp;
      <a href="#M001393">readonly_attributes</a>&nbsp;&nbsp;
      <a href="#M001444">reload</a>&nbsp;&nbsp;
      <a href="#M001469">remove_connection</a>&nbsp;&nbsp;
      <a href="#M001470">require_mysql</a>&nbsp;&nbsp;
      <a href="#M001408">reset_column_information</a>&nbsp;&nbsp;
      <a href="#M001424">sanitize_sql_array</a>&nbsp;&nbsp;
      <a href="#M001421">sanitize_sql_for_assignment</a>&nbsp;&nbsp;
      <a href="#M001420">sanitize_sql_for_conditions</a>&nbsp;&nbsp;
      <a href="#M001423">sanitize_sql_hash_for_assignment</a>&nbsp;&nbsp;
      <a href="#M001422">sanitize_sql_hash_for_conditions</a>&nbsp;&nbsp;
      <a href="#M001430">save</a>&nbsp;&nbsp;
      <a href="#M001431">save!</a>&nbsp;&nbsp;
      <a href="#M001394">serialize</a>&nbsp;&nbsp;
      <a href="#M001395">serialized_attributes</a>&nbsp;&nbsp;
      <a href="#M001401">set_inheritance_column</a>&nbsp;&nbsp;
      <a href="#M001400">set_primary_key</a>&nbsp;&nbsp;
      <a href="#M001402">set_sequence_name</a>&nbsp;&nbsp;
      <a href="#M001399">set_table_name</a>&nbsp;&nbsp;
      <a href="#M001412">silence</a>&nbsp;&nbsp;
      <a href="#M001403">table_exists?</a>&nbsp;&nbsp;
      <a href="#M001396">table_name</a>&nbsp;&nbsp;
      <a href="#M001427">to_param</a>&nbsp;&nbsp;
      <a href="#M001442">toggle</a>&nbsp;&nbsp;
      <a href="#M001443">toggle!</a>&nbsp;&nbsp;
      <a href="#M001380">update</a>&nbsp;&nbsp;
      <a href="#M001383">update_all</a>&nbsp;&nbsp;
      <a href="#M001435">update_attribute</a>&nbsp;&nbsp;
      <a href="#M001436">update_attributes</a>&nbsp;&nbsp;
      <a href="#M001437">update_attributes!</a>&nbsp;&nbsp;
      <a href="#M001387">update_counters</a>&nbsp;&nbsp;
      <a href="#M001417">with_exclusive_scope</a>&nbsp;&nbsp;
      <a href="#M001416">with_scope</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">VALID_FIND_OPTIONS</td>
          <td>=</td>
          <td class="context-item-value">[ :conditions, :include, :joins, :limit, :offset,                                :order, :select, :readonly, :group, :from, :lock ]</td>
        </tr>
        </table>
      </div>
    </div>

    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_table_name</td>
          <td>-&gt;</td>
          <td class="context-item-value">table_name=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_primary_key</td>
          <td>-&gt;</td>
          <td class="context-item-value">primary_key=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_inheritance_column</td>
          <td>-&gt;</td>
          <td class="context-item-value">inheritance_column=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_sequence_name</td>
          <td>-&gt;</td>
          <td class="context-item-value">sequence_name=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql_for_conditions</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_sql</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql_hash_for_conditions</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_sql_hash</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_conditions</td>
        </tr>
                        </table>
      </div>
    </div>


    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">abstract_class</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc">
Set this to true if this is an abstract class (see abstract_class?).

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001413" class="method-detail">
        <a name="M001413"></a>

        <div class="method-heading">
          <a href="#M001413" class="method-signature">
          <span class="method-name">===</span><span class="method-args">(object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overwrite the default class equality method to provide support for
association proxies.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001413-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001413-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1204</span>
1204:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">===</span>(<span class="ruby-identifier">object</span>)
1205:         <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>)
1206:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001415" class="method-detail">
        <a name="M001415"></a>

        <div class="method-heading">
          <a href="#M001415" class="method-signature">
          <span class="method-name">abstract_class?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns whether this class is a base AR class. If A is a base class and B
descends from A, then B.base_class will return B.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001415-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001415-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1220</span>
1220:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">abstract_class?</span>
1221:         <span class="ruby-identifier">abstract_class</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
1222:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001391" class="method-detail">
        <a name="M001391"></a>

        <div class="method-heading">
          <a href="#M001391" class="method-signature">
          <span class="method-name">attr_accessible</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Similar to the <a href="Base.html#M001390">attr_protected</a> macro, this
protects <a href="Base.html#M001448">attributes</a> of your model from
mass-assignment, such as <tt><a href="Base.html#M001425">new</a>(<a
href="Base.html#M001448">attributes</a>)</tt> and <tt><a
href="Base.html#M001447">attributes=</a>(<a
href="Base.html#M001448">attributes</a>)</tt> however, it does it in the
opposite way. This locks all <a href="Base.html#M001448">attributes</a> and
only allows access to the <a href="Base.html#M001448">attributes</a>
specified. Assignment to <a href="Base.html#M001448">attributes</a> not in
this list will be ignored and need to be set using the direct writer
methods instead. This is meant to protect sensitive <a
href="Base.html#M001448">attributes</a> from being overwritten by URL/form
hackers. If you&#8216;d rather start from an all-open default and restrict
<a href="Base.html#M001448">attributes</a> as needed, have a look at <a
href="Base.html#M001390">attr_protected</a>.
</p>
<h4>Options</h4>
<p>
<tt>*<a href="Base.html#M001448">attributes</a></tt> A comma separated list
of symbols that represent <a href="Base.html#M001404">columns</a>
<em>not</em> to be protected
</p>
<h4>Examples</h4>
<pre>
  class Customer &lt; ActiveRecord::Base
    attr_accessible :name, :nickname
  end

  customer = Customer.new(:name =&gt; &quot;David&quot;, :nickname =&gt; &quot;Dave&quot;, :credit_rating =&gt; &quot;Excellent&quot;)
  customer.credit_rating # =&gt; nil
  customer.attributes = { :name =&gt; &quot;Jolly fellow&quot;, :credit_rating =&gt; &quot;Superb&quot; }
  customer.credit_rating # =&gt; nil

  customer.credit_rating = &quot;Average&quot;
  customer.credit_rating # =&gt; &quot;Average&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001391-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001391-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 853</span>
853:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_accessible</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
854:         <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_accessible&quot;</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">accessible_attributes</span> <span class="ruby-operator">||</span> []))
855:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001390" class="method-detail">
        <a name="M001390"></a>

        <div class="method-heading">
          <a href="#M001390" class="method-signature">
          <span class="method-name">attr_protected</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attributes named in this macro are protected from mass-assignment, such as
<tt><a href="Base.html#M001425">new</a>(<a
href="Base.html#M001448">attributes</a>)</tt> and <tt><a
href="Base.html#M001447">attributes=</a>(<a
href="Base.html#M001448">attributes</a>)</tt>. Their assignment will simply
be ignored. Instead, you can use the direct writer methods to do
assignment. This is meant to protect sensitive <a
href="Base.html#M001448">attributes</a> from being overwritten by URL/form
hackers. Example:
</p>
<pre>
  class Customer &lt; ActiveRecord::Base
    attr_protected :credit_rating
  end

  customer = Customer.new(&quot;name&quot; =&gt; David, &quot;credit_rating&quot; =&gt; &quot;Excellent&quot;)
  customer.credit_rating # =&gt; nil
  customer.attributes = { &quot;description&quot; =&gt; &quot;Jolly fellow&quot;, &quot;credit_rating&quot; =&gt; &quot;Superb&quot; }
  customer.credit_rating # =&gt; nil

  customer.credit_rating = &quot;Average&quot;
  customer.credit_rating # =&gt; &quot;Average&quot;
</pre>
<p>
To start from an all-closed default and enable <a
href="Base.html#M001448">attributes</a> as needed, have a look at <a
href="Base.html#M001391">attr_accessible</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001390-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001390-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 819</span>
819:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_protected</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
820:         <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_protected&quot;</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">protected_attributes</span> <span class="ruby-operator">||</span> []))
821:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001392" class="method-detail">
        <a name="M001392"></a>

        <div class="method-heading">
          <a href="#M001392" class="method-signature">
          <span class="method-name">attr_readonly</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attributes listed as readonly can be set for a <a
href="Base.html#M001425">new</a> record, but will be ignored in database
updates afterwards.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001392-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001392-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 863</span>
863:        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_readonly</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
864:          <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_readonly&quot;</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">readonly_attributes</span> <span class="ruby-operator">||</span> []))
865:        <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001414" class="method-detail">
        <a name="M001414"></a>

        <div class="method-heading">
          <a href="#M001414" class="method-signature">
          <span class="method-name">base_class</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the base AR subclass that this class descends from. If A extends
AR::Base, A.base_class will return A. If B descends from A through some
arbitrarily deep hierarchy, B.base_class will return A.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001414-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001414-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1211</span>
1211:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">base_class</span>
1212:         <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-keyword kw">self</span>)
1213:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001411" class="method-detail">
        <a name="M001411"></a>

        <div class="method-heading">
          <a href="#M001411" class="method-signature">
          <span class="method-name">benchmark</span><span class="method-args">(title, log_level = Logger::DEBUG, use_silence = true) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Log and <a href="Base.html#M001411">benchmark</a> multiple statements in a
single block. Example:
</p>
<pre>
  Project.benchmark(&quot;Creating project&quot;) do
    project = Project.create(&quot;name&quot; =&gt; &quot;stuff&quot;)
    project.create_manager(&quot;name&quot; =&gt; &quot;David&quot;)
    project.milestones &lt;&lt; Milestone.find(:all)
  end
</pre>
<p>
The <a href="Base.html#M001411">benchmark</a> is only recorded if the
current level of the logger matches the <tt>log_level</tt>, which makes it
easy to include benchmarking statements in production software that will
remain inexpensive because the <a href="Base.html#M001411">benchmark</a>
will only be conducted if the log level is low enough.
</p>
<p>
The logging of the multiple statements is turned off unless
<tt>use_silence</tt> is set to false.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001411-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001411-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1184</span>
1184:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">title</span>, <span class="ruby-identifier">log_level</span> = <span class="ruby-constant">Logger</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-identifier">use_silence</span> = <span class="ruby-keyword kw">true</span>)
1185:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">log_level</span>
1186:           <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
1187:           <span class="ruby-identifier">seconds</span> = <span class="ruby-constant">Benchmark</span>.<span class="ruby-identifier">realtime</span> { <span class="ruby-identifier">result</span> = <span class="ruby-identifier">use_silence</span> <span class="ruby-value">? </span><span class="ruby-identifier">silence</span> { <span class="ruby-keyword kw">yield</span> } <span class="ruby-operator">:</span> <span class="ruby-keyword kw">yield</span> }
1188:           <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">log_level</span>, <span class="ruby-node">&quot;#{title} (#{'%.5f' % seconds})&quot;</span>)
1189:           <span class="ruby-identifier">result</span>
1190:         <span class="ruby-keyword kw">else</span>
1191:           <span class="ruby-keyword kw">yield</span>
1192:         <span class="ruby-keyword kw">end</span>
1193:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001464" class="method-detail">
        <a name="M001464"></a>

        <div class="method-heading">
          <a href="#M001464" class="method-signature">
          <span class="method-name">clear_active_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the cache which maps classes to connections.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001464-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001464-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 84</span>
84:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_active_connections!</span>
85:         <span class="ruby-identifier">clear_cache!</span>(<span class="ruby-ivar">@@active_connections</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
86:           <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">disconnect!</span>
87:         <span class="ruby-keyword kw">end</span>
88:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001465" class="method-detail">
        <a name="M001465"></a>

        <div class="method-heading">
          <a href="#M001465" class="method-signature">
          <span class="method-name">clear_reloadable_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the cache which maps classes
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001465-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001465-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 91</span>
 91:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_reloadable_connections!</span>
 92:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@allow_concurrency</span>
 93:           <span class="ruby-comment cmt"># With concurrent connections @@active_connections is</span>
 94:           <span class="ruby-comment cmt"># a hash keyed by thread id.</span>
 95:           <span class="ruby-ivar">@@active_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">thread_id</span>, <span class="ruby-identifier">conns</span><span class="ruby-operator">|</span>
 96:             <span class="ruby-identifier">conns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
 97:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">requires_reloading?</span>
 98:                 <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">disconnect!</span>
 99:                 <span class="ruby-ivar">@@active_connections</span>[<span class="ruby-identifier">thread_id</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">name</span>)
100:               <span class="ruby-keyword kw">end</span>
101:             <span class="ruby-keyword kw">end</span>
102:           <span class="ruby-keyword kw">end</span>
103:         <span class="ruby-keyword kw">else</span>
104:           <span class="ruby-ivar">@@active_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
105:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">requires_reloading?</span>
106:               <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">disconnect!</span>
107:               <span class="ruby-ivar">@@active_connections</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">name</span>)
108:             <span class="ruby-keyword kw">end</span>
109:           <span class="ruby-keyword kw">end</span>
110:         <span class="ruby-keyword kw">end</span>
111:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001406" class="method-detail">
        <a name="M001406"></a>

        <div class="method-heading">
          <a href="#M001406" class="method-signature">
          <span class="method-name">column_names</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column names as strings.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001406-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001406-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1092</span>
1092:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">column_names</span>
1093:         <span class="ruby-ivar">@column_names</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span> }
1094:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001404" class="method-detail">
        <a name="M001404"></a>

        <div class="method-heading">
          <a href="#M001404" class="method-signature">
          <span class="method-name">columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column objects for the table associated with this
class.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001404-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001404-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1078</span>
1078:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns</span>
1079:         <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@columns</span>
1080:           <span class="ruby-ivar">@columns</span> = <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">columns</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{name} Columns&quot;</span>)
1081:           <span class="ruby-ivar">@columns</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">primary</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">primary_key</span>}
1082:         <span class="ruby-keyword kw">end</span>
1083:         <span class="ruby-ivar">@columns</span>
1084:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001405" class="method-detail">
        <a name="M001405"></a>

        <div class="method-heading">
          <a href="#M001405" class="method-signature">
          <span class="method-name">columns_hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001457">hash</a> of column objects for the
table associated with this class.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001405-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001405-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1087</span>
1087:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns_hash</span>
1088:         <span class="ruby-ivar">@columns_hash</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">inject</span>({}) { <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">column</span>; <span class="ruby-identifier">hash</span> }
1089:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001468" class="method-detail">
        <a name="M001468"></a>

        <div class="method-heading">
          <a href="#M001468" class="method-signature">
          <span class="method-name">connected?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if a <a href="Base.html#M001463">connection</a> that&#8216;s
accessible to this class has already been opened.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001468-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001468-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 268</span>
268:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connected?</span>
269:       <span class="ruby-identifier">active_connections</span>[<span class="ruby-identifier">active_connection_name</span>] <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
270:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001463" class="method-detail">
        <a name="M001463"></a>

        <div class="method-heading">
          <a href="#M001463" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Base.html#M001463">connection</a> currently associated
with the class. This can also be used to &quot;borrow&quot; the <a
href="Base.html#M001463">connection</a> to do database work unrelated to
any of the specific Active Records.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001463-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001463-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 73</span>
73:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>
74:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@active_connection_name</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">conn</span> = <span class="ruby-identifier">active_connections</span>[<span class="ruby-ivar">@active_connection_name</span>])
75:           <span class="ruby-identifier">conn</span>
76:         <span class="ruby-keyword kw">else</span>
77:           <span class="ruby-comment cmt"># retrieve_connection sets the cache key.</span>
78:           <span class="ruby-identifier">conn</span> = <span class="ruby-identifier">retrieve_connection</span>
79:           <span class="ruby-identifier">active_connections</span>[<span class="ruby-ivar">@active_connection_name</span>] = <span class="ruby-identifier">conn</span>
80:         <span class="ruby-keyword kw">end</span>
81:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001407" class="method-detail">
        <a name="M001407"></a>

        <div class="method-heading">
          <a href="#M001407" class="method-signature">
          <span class="method-name">content_columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column objects where the primary <a
href="Base.html#M001426">id</a>, all <a
href="Base.html#M001404">columns</a> ending in &quot;_id&quot; or
&quot;_count&quot;, and <a href="Base.html#M001404">columns</a> used for
single table inheritance have been removed.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001407-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001407-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1098</span>
1098:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_columns</span>
1099:         <span class="ruby-ivar">@content_columns</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">reject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">primary</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(_id|_count)$/</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">inheritance_column</span> }
1100:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001386" class="method-detail">
        <a name="M001386"></a>

        <div class="method-heading">
          <a href="#M001386" class="method-signature">
          <span class="method-name">count_by_sql</span><span class="method-args">(sql)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the result of an SQL statement that should only include a COUNT(*)
in the SELECT part. The use of this method should be restricted to
complicated SQL queries that can&#8216;t be executed using the
ActiveRecord::Calculations class methods. Look into those before using
this.
</p>
<h4>Options</h4>
<p>
<tt>sql</tt>: An SQL statement which should return a count query from the
database, see the example below
</p>
<h4>Examples</h4>
<pre>
  Product.count_by_sql &quot;SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001386-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001386-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 729</span>
729:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count_by_sql</span>(<span class="ruby-identifier">sql</span>)
730:         <span class="ruby-identifier">sql</span> = <span class="ruby-identifier">sanitize_conditions</span>(<span class="ruby-identifier">sql</span>)
731:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">select_value</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Count&quot;</span>).<span class="ruby-identifier">to_i</span>
732:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001379" class="method-detail">
        <a name="M001379"></a>

        <div class="method-heading">
          <a href="#M001379" class="method-signature">
          <span class="method-name">create</span><span class="method-args">(attributes = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates an object (or multiple objects) and saves it to the database, if
validations pass. The resulting object is returned whether the object was
saved successfully to the database or not.
</p>
<p>
The <tt><a href="Base.html#M001448">attributes</a></tt> parameter can be
either be a Hash or an Array of Hashes. These Hashes describe the <a
href="Base.html#M001448">attributes</a> on the objects that are to be
created.
</p>
<h4>Examples</h4>
<pre>
  # Create a single new object
  User.create(:first_name =&gt; 'Jamie')
  # Create an Array of new objects
  User.create([{:first_name =&gt; 'Jamie'}, {:first_name =&gt; 'Jeremy'}])
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001379-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001379-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 567</span>
567:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">attributes</span> = <span class="ruby-keyword kw">nil</span>)
568:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
569:           <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">attr</span>) }
570:         <span class="ruby-keyword kw">else</span>
571:           <span class="ruby-identifier">object</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>)
572:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">save</span>
573:           <span class="ruby-identifier">object</span>
574:         <span class="ruby-keyword kw">end</span>
575:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001389" class="method-detail">
        <a name="M001389"></a>

        <div class="method-heading">
          <a href="#M001389" class="method-signature">
          <span class="method-name">decrement_counter</span><span class="method-args">(counter_name, id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decrement a number field by one, usually representing a count.
</p>
<p>
This works the same as <a href="Base.html#M001388">increment_counter</a>
but reduces the column value by 1 instead of increasing it.
</p>
<h4>Options</h4>
<p>
<tt>counter_name</tt> The name of the field that should be decremented
<tt><a href="Base.html#M001426">id</a></tt> The <a
href="Base.html#M001426">id</a> of the object that should be decremented
</p>
<h4>Examples</h4>
<pre>
  # Decrement the post_count column for the record with an id of 5
  DiscussionBoard.decrement_counter(:post_count, 5)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001389-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001389-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 797</span>
797:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement_counter</span>(<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">id</span>)
798:         <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counter_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>)
799:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001381" class="method-detail">
        <a name="M001381"></a>

        <div class="method-heading">
          <a href="#M001381" class="method-signature">
          <span class="method-name">delete</span><span class="method-args">(id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delete an object (or multiple objects) where the <tt><a
href="Base.html#M001426">id</a></tt> given matches the <a
href="Base.html#M001397">primary_key</a>. A SQL <tt>DELETE</tt> command is
executed on the database which means that no callbacks are fired off
running this. This is an efficient method of deleting records that
don&#8216;t need cleaning up after or other actions to be taken.
</p>
<p>
Objects are <em>not</em> instantiated with this method.
</p>
<h4>Options</h4>
<p>
<tt><a href="Base.html#M001426">id</a></tt> Can be either an Integer or an
Array of Integers
</p>
<h4>Examples</h4>
<pre>
  # Delete a single object
  Todo.delete(1)

  # Delete multiple objects
  todos = [1,2,3]
  Todo.delete(todos)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001381-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001381-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 622</span>
622:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">id</span>)
623:         <span class="ruby-identifier">delete_all</span>([ <span class="ruby-node">&quot;#{connection.quote_column_name(primary_key)} IN (?)&quot;</span>, <span class="ruby-identifier">id</span> ])
624:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001385" class="method-detail">
        <a name="M001385"></a>

        <div class="method-heading">
          <a href="#M001385" class="method-signature">
          <span class="method-name">delete_all</span><span class="method-args">(conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the records matching <tt>conditions</tt> without instantiating the
records first, and hence not calling the <a
href="Base.html#M001382">destroy</a> method and invoking callbacks. This is
a single SQL query, much more efficient than <a
href="Base.html#M001384">destroy_all</a>.
</p>
<h4>Options</h4>
<p>
<tt>conditions</tt> Conditions are specified the same way as with <tt><a
href="Base.html#M001376">find</a></tt> method.
</p>
<h4>Example</h4>
<pre>
  Post.delete_all &quot;person_id = 5 AND (category = 'Something' OR category = 'Else')&quot;
</pre>
<p>
This deletes the affected posts all at once with a single DELETE query. If
you need to <a href="Base.html#M001382">destroy</a> dependent associations
or call your before_ or after_destroy callbacks, use the <tt><a
href="Base.html#M001384">destroy_all</a></tt> method instead.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001385-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001385-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 712</span>
712:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_all</span>(<span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
713:         <span class="ruby-identifier">sql</span> = <span class="ruby-node">&quot;DELETE FROM #{quoted_table_name} &quot;</span>
714:         <span class="ruby-identifier">add_conditions!</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">scope</span>(<span class="ruby-identifier">:find</span>))
715:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Delete all&quot;</span>)
716:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001409" class="method-detail">
        <a name="M001409"></a>

        <div class="method-heading">
          <a href="#M001409" class="method-signature">
          <span class="method-name">descends_from_active_record?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if this isn&#8216;t a concrete subclass needing a STI type condition.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001409-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001409-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1134</span>
1134:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">descends_from_active_record?</span>
1135:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">abstract_class?</span>
1136:           <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">descends_from_active_record?</span>
1137:         <span class="ruby-keyword kw">else</span>
1138:           <span class="ruby-identifier">superclass</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">columns_hash</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">inheritance_column</span>)
1139:         <span class="ruby-keyword kw">end</span>
1140:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001382" class="method-detail">
        <a name="M001382"></a>

        <div class="method-heading">
          <a href="#M001382" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">(id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destroy an object (or multiple objects) that has the given <a
href="Base.html#M001426">id</a>, the object is instantiated first,
therefore all callbacks and filters are fired off before the object is
deleted. This method is less efficient than ActiveRecord#delete but allows
cleanup methods and other actions to be run.
</p>
<p>
This essentially finds the object (or multiple objects) with the given <a
href="Base.html#M001426">id</a>, creates a <a
href="Base.html#M001425">new</a> object from the <a
href="Base.html#M001448">attributes</a>, and then calls <a
href="Base.html#M001382">destroy</a> on it.
</p>
<h4>Options</h4>
<p>
<tt><a href="Base.html#M001426">id</a></tt> Can be either an Integer or an
Array of Integers
</p>
<h4>Examples</h4>
<pre>
  # Destroy a single object
  Todo.destroy(1)

  # Destroy multiple objects
  todos = [1,2,3]
  Todo.destroy(todos)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001382-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001382-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 645</span>
645:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">id</span>)
646:         <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">id</span>) } <span class="ruby-operator">:</span> <span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>).<span class="ruby-identifier">destroy</span>
647:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001384" class="method-detail">
        <a name="M001384"></a>

        <div class="method-heading">
          <a href="#M001384" class="method-signature">
          <span class="method-name">destroy_all</span><span class="method-args">(conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destroys the records matching <tt>conditions</tt> by instantiating each
record and calling the <a href="Base.html#M001382">destroy</a> method. This
means at least 2*N database queries to <a
href="Base.html#M001382">destroy</a> N records, so avoid <a
href="Base.html#M001384">destroy_all</a> if you are deleting many records.
If you want to simply <a href="Base.html#M001381">delete</a> records
without worrying about dependent associations or callbacks, use the much
faster <tt><a href="Base.html#M001385">delete_all</a></tt> method instead.
</p>
<h4>Options</h4>
<p>
<tt>conditions</tt> Conditions are specified the same way as with <tt><a
href="Base.html#M001376">find</a></tt> method.
</p>
<h4>Example</h4>
<pre>
  Person.destroy_all &quot;last_login &lt; '2004-04-04'&quot;
</pre>
<p>
This loads and destroys each person one by one, including its dependent
associations and before_ and after_destroy callbacks.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001384-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001384-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 694</span>
694:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy_all</span>(<span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
695:         <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conditions</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">destroy</span> }
696:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001467" class="method-detail">
        <a name="M001467"></a>

        <div class="method-heading">
          <a href="#M001467" class="method-signature">
          <span class="method-name">establish_connection</span><span class="method-args">(spec = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Establishes the <a href="Base.html#M001463">connection</a> to the database.
Accepts a <a href="Base.html#M001457">hash</a> as input where the :adapter
key must be specified with the name of a database adapter (in lower-case)
example for regular databases (MySQL, Postgresql, etc):
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    :adapter  =&gt; &quot;mysql&quot;,
    :host     =&gt; &quot;localhost&quot;,
    :username =&gt; &quot;myuser&quot;,
    :password =&gt; &quot;mypass&quot;,
    :database =&gt; &quot;somedatabase&quot;
  )
</pre>
<p>
Example for SQLite database:
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    :adapter =&gt; &quot;sqlite&quot;,
    :database  =&gt; &quot;path/to/dbfile&quot;
  )
</pre>
<p>
Also accepts keys as strings (for parsing from yaml for example):
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    &quot;adapter&quot; =&gt; &quot;sqlite&quot;,
    &quot;database&quot;  =&gt; &quot;path/to/dbfile&quot;
  )
</pre>
<p>
The exceptions <a href="AdapterNotSpecified.html">AdapterNotSpecified</a>,
<a href="AdapterNotFound.html">AdapterNotFound</a> and ArgumentError may be
returned on an error.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001467-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001467-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 204</span>
204:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">spec</span> = <span class="ruby-keyword kw">nil</span>)
205:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">spec</span>
206:         <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>
207:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-constant">RAILS_ENV</span>
208:           <span class="ruby-identifier">establish_connection</span>(<span class="ruby-constant">RAILS_ENV</span>)
209:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">ConnectionSpecification</span>
210:           <span class="ruby-identifier">clear_active_connection_name</span>
211:           <span class="ruby-ivar">@active_connection_name</span> = <span class="ruby-identifier">name</span>
212:           <span class="ruby-ivar">@@defined_connections</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">spec</span>
213:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Symbol</span>, <span class="ruby-constant">String</span>
214:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">configuration</span> = <span class="ruby-identifier">configurations</span>[<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">to_s</span>]
215:             <span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">configuration</span>)
216:           <span class="ruby-keyword kw">else</span>
217:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span>, <span class="ruby-node">&quot;#{spec} database is not configured&quot;</span>
218:           <span class="ruby-keyword kw">end</span>
219:         <span class="ruby-keyword kw">else</span>
220:           <span class="ruby-identifier">spec</span> = <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">symbolize_keys</span>
221:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">:adapter</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span>, <span class="ruby-value str">&quot;database configuration does not specify adapter&quot;</span> <span class="ruby-keyword kw">end</span>
222: 
223:           <span class="ruby-keyword kw">begin</span>
224:             <span class="ruby-identifier">require</span> <span class="ruby-value str">'rubygems'</span>
225:             <span class="ruby-identifier">gem</span> <span class="ruby-node">&quot;activerecord-#{spec[:adapter]}-adapter&quot;</span>
226:             <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;active_record/connection_adapters/#{spec[:adapter]}_adapter&quot;</span>
227:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
228:             <span class="ruby-keyword kw">begin</span>
229:               <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;active_record/connection_adapters/#{spec[:adapter]}_adapter&quot;</span>
230:             <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
231:               <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{$!})&quot;</span>
232:             <span class="ruby-keyword kw">end</span>
233:           <span class="ruby-keyword kw">end</span>
234: 
235:           <span class="ruby-identifier">adapter_method</span> = <span class="ruby-node">&quot;#{spec[:adapter]}_connection&quot;</span>
236:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">adapter_method</span>)
237:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotFound</span>, <span class="ruby-node">&quot;database configuration specifies nonexistent #{spec[:adapter]} adapter&quot;</span>
238:           <span class="ruby-keyword kw">end</span>
239: 
240:           <span class="ruby-identifier">remove_connection</span>
241:           <span class="ruby-identifier">establish_connection</span>(<span class="ruby-constant">ConnectionSpecification</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">spec</span>, <span class="ruby-identifier">adapter_method</span>))
242:       <span class="ruby-keyword kw">end</span>
243:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001378" class="method-detail">
        <a name="M001378"></a>

        <div class="method-heading">
          <a href="#M001378" class="method-signature">
          <span class="method-name">exists?</span><span class="method-args">(id_or_conditions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks whether a record exists in the database that matches conditions
given. These conditions can either be a single integer representing a
primary key <a href="Base.html#M001426">id</a> to be found, or a condition
to be matched like using ActiveRecord#find.
</p>
<p>
The <tt>id_or_conditions</tt> parameter can be an Integer or a String if
you want to search the primary key column of the table for a matching <a
href="Base.html#M001426">id</a>, or if you&#8216;re looking to match
against a condition you can use an Array or a Hash.
</p>
<p>
Possible gotcha: You can&#8216;t pass in a condition as a string e.g.
&quot;name = &#8216;Jamie&#8217;&quot;, this would be sanitized and then
queried against the primary key column as &quot;<a
href="Base.html#M001426">id</a> = &#8216;name = \&#8217;Jamie&quot;
</p>
<h4>Examples</h4>
<pre>
  Person.exists?(5)
  Person.exists?('5')
  Person.exists?(:name =&gt; &quot;David&quot;)
  Person.exists?(['name LIKE ?', &quot;%#{query}%&quot;])
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001378-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001378-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 551</span>
551:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">id_or_conditions</span>)
552:         <span class="ruby-operator">!</span><span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:select</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{quoted_table_name}.#{primary_key}&quot;</span>,
553:               <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">expand_id_conditions</span>(<span class="ruby-identifier">id_or_conditions</span>)).<span class="ruby-identifier">nil?</span>
554:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001376" class="method-detail">
        <a name="M001376"></a>

        <div class="method-heading">
          <a href="#M001376" class="method-signature">
          <span class="method-name">find</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Find operates with three different retrieval approaches:
</p>
<ul>
<li>Find by <a href="Base.html#M001426">id</a>: This can either be a specific
<a href="Base.html#M001426">id</a> (1), a list of ids (1, 5, 6), or an
array of ids ([5, 6, 10]). If no record can be found for all of the listed
ids, then <a href="RecordNotFound.html">RecordNotFound</a> will be raised.

</li>
<li>Find first: This will return the first record matched by the options used.
These options can either be specific conditions or merely an order. If no
record can be matched, nil is returned.

</li>
<li>Find all: This will return all the records matched by the options used. If
no records are found, an empty array is returned.

</li>
</ul>
<p>
All approaches accept an options <a href="Base.html#M001457">hash</a> as
their last parameter. The options are:
</p>
<ul>
<li><tt>:conditions</tt>: An SQL fragment like &quot;administrator = 1&quot; or
[ &quot;user_name = ?&quot;, username ]. See conditions in the intro.

</li>
<li><tt>:order</tt>: An SQL fragment like &quot;created_at DESC, name&quot;.

</li>
<li><tt>:group</tt>: An attribute name by which the result should be grouped.
Uses the GROUP BY SQL-clause.

</li>
<li><tt>:limit</tt>: An integer determining the limit on the number of rows
that should be returned.

</li>
<li><tt>:offset</tt>: An integer determining the offset from where the rows
should be fetched. So at 5, it would skip rows 0 through 4.

</li>
<li><tt>:joins</tt>: Either an SQL fragment for additional joins like
&quot;LEFT JOIN comments ON comments.post_id = <a
href="Base.html#M001426">id</a>&quot; (rarely needed) or named associations
in the same form used for the :include option, which will perform an INNER
JOIN on the associated table(s). If the value is a string, then the records
will be returned read-only since they will have <a
href="Base.html#M001448">attributes</a> that do not correspond to the
table&#8216;s <a href="Base.html#M001404">columns</a>. Pass :readonly =&gt;
false to override.

</li>
<li><tt>:include</tt>: Names associations that should be loaded alongside using
LEFT OUTER JOINs. The symbols named refer to already defined associations.
See eager loading under Associations.

</li>
<li><tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be
changed if you, for example, want to do a join but not include the joined
<a href="Base.html#M001404">columns</a>.

</li>
<li><tt>:from</tt>: By default, this is the table name of the class, but can be
changed to an alternate table name (or even the name of a database view).

</li>
<li><tt>:readonly</tt>: Mark the returned records read-only so they cannot be
saved or updated.

</li>
<li><tt>:lock</tt>: An SQL fragment like &quot;FOR UPDATE&quot; or &quot;LOCK
IN SHARE MODE&quot;. :lock =&gt; true gives <a
href="Base.html#M001463">connection</a>&#8216;s default exclusive lock,
usually &quot;FOR UPDATE&quot;.

</li>
</ul>
<p>
Examples for <a href="Base.html#M001376">find</a> by <a
href="Base.html#M001426">id</a>:
</p>
<pre>
  Person.find(1)       # returns the object for ID = 1
  Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
  Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
  Person.find([1])     # returns an array for the object with ID = 1
  Person.find(1, :conditions =&gt; &quot;administrator = 1&quot;, :order =&gt; &quot;created_on DESC&quot;)
</pre>
<p>
Note that returned records may not be in the same order as the ids you
provide since database rows are unordered. Give an explicit :order to
ensure the results are sorted.
</p>
<p>
Examples for <a href="Base.html#M001376">find</a> first:
</p>
<pre>
  Person.find(:first) # returns the first object fetched by SELECT * FROM people
  Person.find(:first, :conditions =&gt; [ &quot;user_name = ?&quot;, user_name])
  Person.find(:first, :order =&gt; &quot;created_on DESC&quot;, :offset =&gt; 5)
</pre>
<p>
Examples for <a href="Base.html#M001376">find</a> all:
</p>
<pre>
  Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people
  Person.find(:all, :conditions =&gt; [ &quot;category IN (?)&quot;, categories], :limit =&gt; 50)
  Person.find(:all, :offset =&gt; 10, :limit =&gt; 10)
  Person.find(:all, :include =&gt; [ :account, :friends ])
  Person.find(:all, :group =&gt; &quot;category&quot;)
</pre>
<p>
Example for <a href="Base.html#M001376">find</a> with a lock. Imagine two
concurrent transactions: each will read person.visits == 2, add 1 to it,
and <a href="Base.html#M001430">save</a>, resulting in two saves of
person.visits = 3. By locking the row, the second transaction has to wait
until the first is finished; we get the expected person.visits == 4.
</p>
<pre>
  Person.transaction do
    person = Person.find(1, :lock =&gt; true)
    person.visits += 1
    person.save!
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001376-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001376-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 496</span>
496:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
497:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
498:         <span class="ruby-identifier">validate_find_options</span>(<span class="ruby-identifier">options</span>)
499:         <span class="ruby-identifier">set_readonly_option!</span>(<span class="ruby-identifier">options</span>)
500: 
501:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>
502:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:first</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_initial</span>(<span class="ruby-identifier">options</span>)
503:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:all</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_every</span>(<span class="ruby-identifier">options</span>)
504:           <span class="ruby-keyword kw">else</span>             <span class="ruby-identifier">find_from_ids</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>)
505:         <span class="ruby-keyword kw">end</span>
506:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001377" class="method-detail">
        <a name="M001377"></a>

        <div class="method-heading">
          <a href="#M001377" class="method-signature">
          <span class="method-name">find_by_sql</span><span class="method-args">(sql)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Executes a custom sql query against your database and returns all the
results. The results will be returned as an array with <a
href="Base.html#M001404">columns</a> requested encapsulated as <a
href="Base.html#M001448">attributes</a> of the model you call this method
from. If you call +Product.find_by_sql+ then the results will be returned
in a Product object with the <a href="Base.html#M001448">attributes</a> you
specified in the SQL query.
</p>
<p>
If you call a complicated SQL query which spans multiple tables the <a
href="Base.html#M001404">columns</a> specified by the SELECT will be <a
href="Base.html#M001448">attributes</a> of the model, whether or not they
are <a href="Base.html#M001404">columns</a> of the corresponding table.
</p>
<p>
The <tt>sql</tt> parameter is a full sql query as a string. It will be
called as is, there will be no database agnostic conversions performed.
This should be a last resort because using, for example, MySQL specific
terms will lock you to using that particular database engine or require you
to change your call if you switch engines
</p>
<h4>Examples</h4>
<pre>
  # A simple sql query spanning multiple tables
  Post.find_by_sql &quot;SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id&quot;
  &gt; [#&lt;Post:0x36bff9c @attributes={&quot;title&quot;=&gt;&quot;Ruby Meetup&quot;, &quot;first_name&quot;=&gt;&quot;Quentin&quot;}&gt;, ...]

  # You can use the same string replacement techniques as you can with ActiveRecord#find
  Post.find_by_sql [&quot;SELECT title FROM posts WHERE author = ? AND created &gt; ?&quot;, author_id, start_date]
  &gt; [#&lt;Post:0x36bff9c @attributes={&quot;first_name&quot;=&gt;&quot;The Cheap Man Buys Twice&quot;}&gt;, ...]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001377-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001377-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 531</span>
531:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_by_sql</span>(<span class="ruby-identifier">sql</span>)
532:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">select_all</span>(<span class="ruby-identifier">sanitize_sql</span>(<span class="ruby-identifier">sql</span>), <span class="ruby-node">&quot;#{name} Load&quot;</span>).<span class="ruby-identifier">collect!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">record</span><span class="ruby-operator">|</span> <span class="ruby-identifier">instantiate</span>(<span class="ruby-identifier">record</span>) }
533:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001388" class="method-detail">
        <a name="M001388"></a>

        <div class="method-heading">
          <a href="#M001388" class="method-signature">
          <span class="method-name">increment_counter</span><span class="method-args">(counter_name, id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Increment a number field by one, usually representing a count.
</p>
<p>
This is used for caching aggregate values, so that they don&#8216;t need to
be computed every time. For example, a DiscussionBoard may cache post_count
and comment_count otherwise every time the board is shown it would have to
run an SQL query to <a href="Base.html#M001376">find</a> how many posts and
comments there are.
</p>
<h4>Options</h4>
<p>
<tt>counter_name</tt> The name of the field that should be incremented
<tt><a href="Base.html#M001426">id</a></tt> The <a
href="Base.html#M001426">id</a> of the object that should be incremented
</p>
<h4>Examples</h4>
<pre>
  # Increment the post_count column for the record with an id of 5
  DiscussionBoard.increment_counter(:post_count, 5)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001388-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001388-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 780</span>
780:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment_counter</span>(<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">id</span>)
781:         <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counter_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>)
782:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001398" class="method-detail">
        <a name="M001398"></a>

        <div class="method-heading">
          <a href="#M001398" class="method-signature">
          <span class="method-name">inheritance_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Defines the column name for use with single table inheritance &#8212; can
be set in subclasses like so: self.inheritance_column = &quot;type_id&quot;
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001398-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001398-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 973</span>
973:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inheritance_column</span>
974:         <span class="ruby-ivar">@inheritance_column</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">&quot;type&quot;</span>.<span class="ruby-identifier">freeze</span>
975:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001410" class="method-detail">
        <a name="M001410"></a>

        <div class="method-heading">
          <a href="#M001410" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a string like &#8216;Post <a
href="Base.html#M001426">id</a>:integer, title:string, body:text&#8216;
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001410-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001410-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1148</span>
1148:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
1149:         <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span>
1150:           <span class="ruby-keyword kw">super</span>
1151:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">abstract_class?</span>
1152:           <span class="ruby-node">&quot;#{super}(abstract)&quot;</span>
1153:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">table_exists?</span>
1154:           <span class="ruby-identifier">attr_list</span> = <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{c.name}: #{c.type}&quot;</span> } <span class="ruby-operator">*</span> <span class="ruby-value str">', '</span>
1155:           <span class="ruby-node">&quot;#{super}(#{attr_list})&quot;</span>
1156:         <span class="ruby-keyword kw">else</span>
1157:           <span class="ruby-node">&quot;#{super}(Table doesn't exist)&quot;</span>
1158:         <span class="ruby-keyword kw">end</span>
1159:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001425" class="method-detail">
        <a name="M001425"></a>

        <div class="method-heading">
          <a href="#M001425" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(attributes = nil) {|self if block_given?| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
New objects can be instantiated as either empty (pass no construction
parameter) or pre-set with <a href="Base.html#M001448">attributes</a> but
not yet saved (pass a <a href="Base.html#M001457">hash</a> with key names
matching the associated table column names). In both instances, valid
attribute keys are determined by the column names of the associated table
&#8212; hence you can&#8216;t have <a
href="Base.html#M001448">attributes</a> that aren&#8216;t part of the table
<a href="Base.html#M001404">columns</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001425-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001425-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1921</span>
1921:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">attributes</span> = <span class="ruby-keyword kw">nil</span>)
1922:         <span class="ruby-ivar">@attributes</span> = <span class="ruby-identifier">attributes_from_column_definition</span>
1923:         <span class="ruby-ivar">@attributes_cache</span> = {}
1924:         <span class="ruby-ivar">@new_record</span> = <span class="ruby-keyword kw">true</span>
1925:         <span class="ruby-identifier">ensure_proper_type</span>
1926:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">nil?</span>
1927:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:scope</span>, <span class="ruby-identifier">:create</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">att</span>,<span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{att}=&quot;</span>, <span class="ruby-identifier">value</span>) } <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:scoped?</span>, <span class="ruby-identifier">:create</span>)
1928:         <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1929:         <span class="ruby-identifier">callback</span>(<span class="ruby-identifier">:after_initialize</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to_without_attributes?</span>(<span class="ruby-identifier">:after_initialize</span>)
1930:         <span class="ruby-identifier">result</span>
1931:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001397" class="method-detail">
        <a name="M001397"></a>

        <div class="method-heading">
          <a href="#M001397" class="method-signature">
          <span class="method-name">primary_key</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Defines the primary key field &#8212; can be overridden in subclasses.
Overwriting will negate any effect of the primary_key_prefix_type setting,
though.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001397-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001397-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 955</span>
955:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">primary_key</span>
956:         <span class="ruby-identifier">reset_primary_key</span>
957:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001393" class="method-detail">
        <a name="M001393"></a>

        <div class="method-heading">
          <a href="#M001393" class="method-signature">
          <span class="method-name">readonly_attributes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of all the <a href="Base.html#M001448">attributes</a> that
have been specified as readonly.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001393-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001393-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 868</span>
868:        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly_attributes</span>
869:          <span class="ruby-identifier">read_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_readonly&quot;</span>)
870:        <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001469" class="method-detail">
        <a name="M001469"></a>

        <div class="method-heading">
          <a href="#M001469" class="method-signature">
          <span class="method-name">remove_connection</span><span class="method-args">(klass=self)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Remove the <a href="Base.html#M001463">connection</a> for this class. This
will close the active <a href="Base.html#M001463">connection</a> and the
defined <a href="Base.html#M001463">connection</a> (if they exist). The
result can be used as an argument for <a
href="Base.html#M001467">establish_connection</a>, for easily
re-establishing the <a href="Base.html#M001463">connection</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001469-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001469-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 276</span>
276:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">remove_connection</span>(<span class="ruby-identifier">klass</span>=<span class="ruby-keyword kw">self</span>)
277:       <span class="ruby-identifier">spec</span> = <span class="ruby-ivar">@@defined_connections</span>[<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">name</span>]
278:       <span class="ruby-identifier">konn</span> = <span class="ruby-identifier">active_connections</span>[<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">name</span>]
279:       <span class="ruby-ivar">@@defined_connections</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">spec</span> }
280:       <span class="ruby-identifier">active_connections</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">konn</span> }
281:       <span class="ruby-identifier">konn</span>.<span class="ruby-identifier">disconnect!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">konn</span>
282:       <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">config</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">spec</span>
283:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001470" class="method-detail">
        <a name="M001470"></a>

        <div class="method-heading">
          <a href="#M001470" class="method-signature">
          <span class="method-name">require_mysql</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001470-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001470-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 47</span>
47:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_mysql</span>
48:       <span class="ruby-comment cmt"># Include the MySQL driver if one hasn't already been loaded</span>
49:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-constant">Mysql</span>
50:         <span class="ruby-keyword kw">begin</span>
51:           <span class="ruby-identifier">require_library_or_gem</span> <span class="ruby-value str">'mysql'</span>
52:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cannot_require_mysql</span>
53:           <span class="ruby-comment cmt"># Use the bundled Ruby/MySQL driver if no driver is already in place</span>
54:           <span class="ruby-keyword kw">begin</span>
55:             <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span>(
56:               <span class="ruby-value str">&quot;WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. &quot;</span> <span class="ruby-operator">+</span>
57:               <span class="ruby-value str">&quot;Please install the C-based MySQL library instead (gem install mysql).&quot;</span>
58:             ) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">logger</span>
59: 
60:             <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_record/vendor/mysql'</span>
61:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
62:             <span class="ruby-identifier">raise</span> <span class="ruby-identifier">cannot_require_mysql</span>
63:           <span class="ruby-keyword kw">end</span>
64:         <span class="ruby-keyword kw">end</span>
65:       <span class="ruby-keyword kw">end</span>
66: 
67:       <span class="ruby-comment cmt"># Define Mysql::Result.all_hashes</span>
68:       <span class="ruby-constant">MysqlCompat</span>.<span class="ruby-identifier">define_all_hashes_method!</span>
69:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001408" class="method-detail">
        <a name="M001408"></a>

        <div class="method-heading">
          <a href="#M001408" class="method-signature">
          <span class="method-name">reset_column_information</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Resets all the cached information about <a
href="Base.html#M001404">columns</a>, which will cause them to be reloaded
on the next request.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001408-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001408-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1117</span>
1117:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_column_information</span>
1118:         <span class="ruby-identifier">generated_methods</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">undef_method</span>(<span class="ruby-identifier">name</span>) }
1119:         <span class="ruby-ivar">@column_names</span> = <span class="ruby-ivar">@columns</span> = <span class="ruby-ivar">@columns_hash</span> = <span class="ruby-ivar">@content_columns</span> = <span class="ruby-ivar">@dynamic_methods_hash</span> = <span class="ruby-ivar">@generated_methods</span> = <span class="ruby-ivar">@inheritance_column</span> = <span class="ruby-keyword kw">nil</span>
1120:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001394" class="method-detail">
        <a name="M001394"></a>

        <div class="method-heading">
          <a href="#M001394" class="method-signature">
          <span class="method-name">serialize</span><span class="method-args">(attr_name, class_name = Object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
If you have an attribute that needs to be saved to the database as an
object, and retrieved as the same object, then specify the name of that
attribute using this method and it will be handled automatically. The
serialization is done through YAML. If <tt>class_name</tt> is specified,
the serialized object must be of that class on retrieval or <tt><a
href="SerializationTypeMismatch.html">SerializationTypeMismatch</a></tt>
will be raised.
</p>
<h4>Options</h4>
<p>
<tt>attr_name</tt> The field name that should be serialized
<tt>class_name</tt> Optional, class name that the object type should be
equal to
</p>
<h4>Example</h4>
<pre>
  # Serialize a preferences attribute
  class User
    serialize :preferences
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001394-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001394-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 887</span>
887:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serialize</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">class_name</span> = <span class="ruby-constant">Object</span>)
888:         <span class="ruby-identifier">serialized_attributes</span>[<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">class_name</span>
889:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001395" class="method-detail">
        <a name="M001395"></a>

        <div class="method-heading">
          <a href="#M001395" class="method-signature">
          <span class="method-name">serialized_attributes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001457">hash</a> of all the <a
href="Base.html#M001448">attributes</a> that have been specified for
serialization as keys and their class restriction as values.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001395-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001395-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 892</span>
892:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serialized_attributes</span>
893:         <span class="ruby-identifier">read_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_serialized&quot;</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-value str">&quot;attr_serialized&quot;</span>, {})
894:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001401" class="method-detail">
        <a name="M001401"></a>

        <div class="method-heading">
          <a href="#M001401" class="method-signature">
          <span class="method-name">set_inheritance_column</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the inheritance column to use to the given value, or (if
the value # is nil or false) to the value returned by the given block.
</p>
<p>
Example:
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_inheritance_column do
      original_inheritance_column + &quot;_id&quot;
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001401-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001401-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1027</span>
1027:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_inheritance_column</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1028:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:inheritance_column</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1029:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001400" class="method-detail">
        <a name="M001400"></a>

        <div class="method-heading">
          <a href="#M001400" class="method-signature">
          <span class="method-name">set_primary_key</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the primary key column to use to the given value, or (if
the value is nil or false) to the value returned by the given block.
</p>
<p>
Example:
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_primary_key &quot;sysid&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001400-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001400-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1011</span>
1011:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_primary_key</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1012:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:primary_key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1013:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001402" class="method-detail">
        <a name="M001402"></a>

        <div class="method-heading">
          <a href="#M001402" class="method-signature">
          <span class="method-name">set_sequence_name</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the sequence to use when generating ids to the given
value, or (if the value is nil or false) to the value returned by the given
block. This is required for Oracle and is useful for any database which
relies on sequences for primary key generation.
</p>
<p>
If a sequence name is not explicitly set when using Oracle or Firebird, it
will default to the commonly used pattern of: #{<a
href="Base.html#M001396">table_name</a>}_seq
</p>
<p>
If a sequence name is not explicitly set when using PostgreSQL, it will
discover the sequence corresponding to your primary key for you.
</p>
<p>
Example:
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_sequence_name &quot;projectseq&quot;   # default would have been &quot;project_seq&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001402-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001402-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1048</span>
1048:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_sequence_name</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1049:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:sequence_name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1050:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001399" class="method-detail">
        <a name="M001399"></a>

        <div class="method-heading">
          <a href="#M001399" class="method-signature">
          <span class="method-name">set_table_name</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the table name to use to the given value, or (if the value is nil or
false) to the value returned by the given block.
</p>
<p>
Example:
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_table_name &quot;project&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001399-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001399-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 997</span>
997:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_table_name</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
998:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:table_name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
999:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001412" class="method-detail">
        <a name="M001412"></a>

        <div class="method-heading">
          <a href="#M001412" class="method-signature">
          <span class="method-name">silence</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Silences the logger for the duration of the block.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001412-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001412-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1196</span>
1196:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">silence</span>
1197:         <span class="ruby-identifier">old_logger_level</span>, <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> = <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span>, <span class="ruby-constant">Logger</span><span class="ruby-operator">::</span><span class="ruby-constant">ERROR</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span>
1198:         <span class="ruby-keyword kw">yield</span>
1199:       <span class="ruby-keyword kw">ensure</span>
1200:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> = <span class="ruby-identifier">old_logger_level</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span>
1201:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001403" class="method-detail">
        <a name="M001403"></a>

        <div class="method-heading">
          <a href="#M001403" class="method-signature">
          <span class="method-name">table_exists?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Indicates whether the table associated with this class exists
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001403-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001403-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1062</span>
1062:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">table_exists?</span>
1063:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:tables</span>)
1064:           <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">tables</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">table_name</span>
1065:         <span class="ruby-keyword kw">else</span>
1066:           <span class="ruby-comment cmt"># if the connection adapter hasn't implemented tables, there are two crude tests that can be</span>
1067:           <span class="ruby-comment cmt"># used - see if getting column info raises an error, or if the number of columns returned is zero</span>
1068:           <span class="ruby-keyword kw">begin</span>
1069:             <span class="ruby-identifier">reset_column_information</span>
1070:             <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
1071:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">StatementInvalid</span>
1072:             <span class="ruby-keyword kw">false</span>
1073:           <span class="ruby-keyword kw">end</span>
1074:         <span class="ruby-keyword kw">end</span>
1075:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001396" class="method-detail">
        <a name="M001396"></a>

        <div class="method-heading">
          <a href="#M001396" class="method-signature">
          <span class="method-name">table_name</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Guesses the table name (in forced lower-case) based on the name of the
class in the inheritance hierarchy descending directly from ActiveRecord.
So if the hierarchy looks like: Reply &lt; Message &lt; ActiveRecord, then
Message is used to guess the table name even when called on Reply. The
rules used to do the guess are handled by the <a
href="../Inflector.html">Inflector</a> class in Active Support, which knows
almost all common English inflections. You can add <a
href="Base.html#M001425">new</a> inflections in
config/initializers/inflections.rb.
</p>
<p>
Nested classes are given table names prefixed by the singular form of the
parent&#8216;s table name. Enclosing modules are not considered. Examples:
</p>
<pre>
  class Invoice &lt; ActiveRecord::Base; end;
  file                  class               table_name
  invoice.rb            Invoice             invoices

  class Invoice &lt; ActiveRecord::Base; class Lineitem &lt; ActiveRecord::Base; end; end;
  file                  class               table_name
  invoice.rb            Invoice::Lineitem   invoice_lineitems

  module Invoice; class Lineitem &lt; ActiveRecord::Base; end; end;
  file                  class               table_name
  invoice/lineitem.rb   Invoice::Lineitem   lineitems
</pre>
<p>
Additionally, the class-level table_name_prefix is prepended and the
table_name_suffix is appended. So if you have &quot;myapp_&quot; as a
prefix, the table name guess for an Invoice class <a
href="Base.html#M001434">becomes</a> &quot;myapp_invoices&quot;.
Invoice::Lineitem <a href="Base.html#M001434">becomes</a>
&quot;myapp_invoice_lineitems&quot;.
</p>
<p>
You can also overwrite this class method to allow for unguessable links,
such as a Mouse class with a link to a &quot;mice&quot; table. Example:
</p>
<pre>
  class Mouse &lt; ActiveRecord::Base
    set_table_name &quot;mice&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001396-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001396-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 928</span>
928:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">table_name</span>
929:         <span class="ruby-identifier">reset_table_name</span>
930:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001380" class="method-detail">
        <a name="M001380"></a>

        <div class="method-heading">
          <a href="#M001380" class="method-signature">
          <span class="method-name">update</span><span class="method-args">(id, attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates an object (or multiple objects) and saves it to the database, if
validations pass. The resulting object is returned whether the object was
saved successfully to the database or not.
</p>
<h4>Options</h4>
<p>
<tt><a href="Base.html#M001426">id</a></tt> This should be the <a
href="Base.html#M001426">id</a> or an array of ids to be updated <tt><a
href="Base.html#M001448">attributes</a></tt> This should be a Hash of <a
href="Base.html#M001448">attributes</a> to be set on the object, or an
array of Hashes.
</p>
<h4>Examples</h4>
<pre>
  # Updating one record:
  Person.update(15, {:user_name =&gt; 'Samuel', :group =&gt; 'expert'})

  # Updating multiple records:
  people = { 1 =&gt; { &quot;first_name&quot; =&gt; &quot;David&quot; }, 2 =&gt; { &quot;first_name&quot; =&gt; &quot;Jeremy&quot;} }
  Person.update(people.keys, people.values)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001380-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001380-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 593</span>
593:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">attributes</span>)
594:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
595:           <span class="ruby-identifier">idx</span> = <span class="ruby-value">-1</span>
596:           <span class="ruby-identifier">id</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>; <span class="ruby-identifier">update</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">idx</span>]) }
597:         <span class="ruby-keyword kw">else</span>
598:           <span class="ruby-identifier">object</span> = <span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>)
599:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">attributes</span>)
600:           <span class="ruby-identifier">object</span>
601:         <span class="ruby-keyword kw">end</span>
602:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001383" class="method-detail">
        <a name="M001383"></a>

        <div class="method-heading">
          <a href="#M001383" class="method-signature">
          <span class="method-name">update_all</span><span class="method-args">(updates, conditions = nil, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates all records with details given if they match a set of conditions
supplied, limits and order can also be supplied.
</p>
<h4>Options</h4>
<p>
<tt>updates</tt> A String of column and value pairs that will be set on any
records that match conditions <tt>conditions</tt> An SQL fragment like
&quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ].
</p>
<pre>
              See conditions in the intro for more info.
</pre>
<p>
<tt>options</tt> Additional options are :limit and/or :order, see the
examples for usage.
</p>
<h4>Examples</h4>
<pre>
  # Update all billing objects with the 3 different attributes given
  Billing.update_all( &quot;category = 'authorized', approved = 1, author = 'David'&quot; )

  # Update records that match our conditions
  Billing.update_all( &quot;author = 'David'&quot;, &quot;title LIKE '%Rails%'&quot; )

  # Update records that match our conditions but limit it to 5 ordered by date
  Billing.update_all( &quot;author = 'David'&quot;, &quot;title LIKE '%Rails%'&quot;,
                        :order =&gt; 'created_at', :limit =&gt; 5 )
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001383-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001383-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 670</span>
670:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_all</span>(<span class="ruby-identifier">updates</span>, <span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = {})
671:         <span class="ruby-identifier">sql</span>  = <span class="ruby-node">&quot;UPDATE #{table_name} SET #{sanitize_sql_for_assignment(updates)} &quot;</span>
672:         <span class="ruby-identifier">scope</span> = <span class="ruby-identifier">scope</span>(<span class="ruby-identifier">:find</span>)
673:         <span class="ruby-identifier">add_conditions!</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">scope</span>)
674:         <span class="ruby-identifier">add_order!</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:order</span>], <span class="ruby-identifier">scope</span>)
675:         <span class="ruby-identifier">add_limit!</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">scope</span>)
676:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Update&quot;</span>)
677:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001387" class="method-detail">
        <a name="M001387"></a>

        <div class="method-heading">
          <a href="#M001387" class="method-signature">
          <span class="method-name">update_counters</span><span class="method-args">(id, counters)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A generic &quot;counter updater&quot; implementation, intended primarily to
be used by <a href="Base.html#M001388">increment_counter</a> and <a
href="Base.html#M001389">decrement_counter</a>, but which may also be
useful on its own. It simply does a direct SQL <a
href="Base.html#M001380">update</a> for the record with the given ID,
altering the given <a href="Base.html#M001457">hash</a> of counters by the
amount given by the corresponding value:
</p>
<h4>Options</h4>
<p>
<tt><a href="Base.html#M001426">id</a></tt> The <a
href="Base.html#M001426">id</a> of the object you wish to <a
href="Base.html#M001380">update</a> a counter on <tt>counters</tt> An Array
of Hashes containing the names of the fields
</p>
<pre>
            to update as keys and the amount to update the field by as
            values
</pre>
<h4>Examples</h4>
<pre>
  # For the Post with id of 5, decrement the comment_count by 1, and
  # increment the action_count by 1
  Post.update_counters 5, :comment_count =&gt; -1, :action_count =&gt; 1
  # Executes the following SQL:
  # UPDATE posts
  #    SET comment_count = comment_count - 1,
  #        action_count = action_count + 1
  #  WHERE id = 5
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001387-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001387-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 757</span>
757:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
758:         <span class="ruby-identifier">updates</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">inject</span>([]) { <span class="ruby-operator">|</span><span class="ruby-identifier">list</span>, (<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">increment</span>)<span class="ruby-operator">|</span>
759:           <span class="ruby-identifier">sign</span> = <span class="ruby-identifier">increment</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;+&quot;</span>
760:           <span class="ruby-identifier">list</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{connection.quote_column_name(counter_name)} = #{connection.quote_column_name(counter_name)} #{sign} #{increment.abs}&quot;</span>
761:         }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;, &quot;</span>)
762:         <span class="ruby-identifier">update_all</span>(<span class="ruby-identifier">updates</span>, <span class="ruby-node">&quot;#{connection.quote_column_name(primary_key)} = #{quote_value(id)}&quot;</span>)
763:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Class methods</h3>

      <div id="method-M001419" class="method-detail">
        <a name="M001419"></a>

        <div class="method-heading">
          <a href="#M001419" class="method-signature">
          <span class="method-name">class_of_active_record_descendant</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the class descending directly from ActiveRecord in the inheritance
hierarchy.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001419-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001419-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1755</span>
1755:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-identifier">klass</span>)
1756:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">abstract_class?</span>
1757:             <span class="ruby-identifier">klass</span>
1758:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">nil?</span>
1759:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-node">&quot;#{name} doesn't belong in a hierarchy descending from ActiveRecord&quot;</span>
1760:           <span class="ruby-keyword kw">else</span>
1761:             <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>)
1762:           <span class="ruby-keyword kw">end</span>
1763:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001418" class="method-detail">
        <a name="M001418"></a>

        <div class="method-heading">
          <a href="#M001418" class="method-signature">
          <span class="method-name">compute_type</span><span class="method-args">(type_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the class type of the record using the current module as a prefix.
So descendents of MyApp::Business::Account would appear as
MyApp::Business::AccountSubclass.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001418-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001418-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1745</span>
1745:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compute_type</span>(<span class="ruby-identifier">type_name</span>)
1746:           <span class="ruby-identifier">modularized_name</span> = <span class="ruby-identifier">type_name_with_module</span>(<span class="ruby-identifier">type_name</span>)
1747:           <span class="ruby-keyword kw">begin</span>
1748:             <span class="ruby-identifier">class_eval</span>(<span class="ruby-identifier">modularized_name</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>)
1749:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
1750:             <span class="ruby-identifier">class_eval</span>(<span class="ruby-identifier">type_name</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>)
1751:           <span class="ruby-keyword kw">end</span>
1752:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001424" class="method-detail">
        <a name="M001424"></a>

        <div class="method-heading">
          <a href="#M001424" class="method-signature">
          <span class="method-name">sanitize_sql_array</span><span class="method-args">(ary)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array of conditions. The array has each value sanitized and
interpolated into the sql statement.
</p>
<pre>
  [&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001424-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001424-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1835</span>
1835:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">ary</span>)
1836:           <span class="ruby-identifier">statement</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">values</span> = <span class="ruby-identifier">ary</span>
1837:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">statement</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/:\w+/</span>
1838:             <span class="ruby-identifier">replace_named_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
1839:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'?'</span>)
1840:             <span class="ruby-identifier">replace_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
1841:           <span class="ruby-keyword kw">else</span>
1842:             <span class="ruby-identifier">statement</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_string</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>) }
1843:           <span class="ruby-keyword kw">end</span>
1844:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001421" class="method-detail">
        <a name="M001421"></a>

        <div class="method-heading">
          <a href="#M001421" class="method-signature">
          <span class="method-name">sanitize_sql_for_assignment</span><span class="method-args">(assignments)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array, <a href="Base.html#M001457">hash</a>, or string of sql
conditions and sanitizes them into a valid SQL fragment for a SET clause.
</p>
<pre>
  { :name =&gt; nil, :group_id =&gt; 4 }  returns &quot;name = NULL , group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001421-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001421-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1787</span>
1787:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_for_assignment</span>(<span class="ruby-identifier">assignments</span>)
1788:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">assignments</span>
1789:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">assignments</span>)
1790:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">assignments</span>)
1791:             <span class="ruby-keyword kw">else</span>        <span class="ruby-identifier">assignments</span>
1792:           <span class="ruby-keyword kw">end</span>
1793:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001420" class="method-detail">
        <a name="M001420"></a>

        <div class="method-heading">
          <a href="#M001420" class="method-signature">
          <span class="method-name">sanitize_sql_for_conditions</span><span class="method-args">(condition)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array, <a href="Base.html#M001457">hash</a>, or string of sql
conditions and sanitizes them into a valid SQL fragment for a WHERE clause.
</p>
<pre>
  [&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
  { :name =&gt; &quot;foo'bar&quot;, :group_id =&gt; 4 }  returns &quot;name='foo''bar' and group_id='4'&quot;
  &quot;name='foo''bar' and group_id='4'&quot; returns &quot;name='foo''bar' and group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001420-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001420-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1775</span>
1775:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_for_conditions</span>(<span class="ruby-identifier">condition</span>)
1776:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">condition</span>
1777:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">condition</span>)
1778:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">condition</span>)
1779:             <span class="ruby-keyword kw">else</span>        <span class="ruby-identifier">condition</span>
1780:           <span class="ruby-keyword kw">end</span>
1781:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001423" class="method-detail">
        <a name="M001423"></a>

        <div class="method-heading">
          <a href="#M001423" class="method-signature">
          <span class="method-name">sanitize_sql_hash_for_assignment</span><span class="method-args">(attrs)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sanitizes a <a href="Base.html#M001457">hash</a> of attribute/value pairs
into SQL conditions for a SET clause.
</p>
<pre>
  { :status =&gt; nil, :group_id =&gt; 1 }
    # =&gt; &quot;status = NULL , group_id = 1&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001423-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001423-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1826</span>
1826:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">attrs</span>)
1827:           <span class="ruby-identifier">conditions</span> = <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
1828:             <span class="ruby-node">&quot;#{connection.quote_column_name(attr)} = #{quote_bound_value(value)}&quot;</span>
1829:           <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">', '</span>)
1830:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001422" class="method-detail">
        <a name="M001422"></a>

        <div class="method-heading">
          <a href="#M001422" class="method-signature">
          <span class="method-name">sanitize_sql_hash_for_conditions</span><span class="method-args">(attrs)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sanitizes a <a href="Base.html#M001457">hash</a> of attribute/value pairs
into SQL conditions for a WHERE clause.
</p>
<pre>
  { :name =&gt; &quot;foo'bar&quot;, :group_id =&gt; 4 }
    # =&gt; &quot;name='foo''bar' and group_id= 4&quot;
  { :status =&gt; nil, :group_id =&gt; [1,2,3] }
    # =&gt; &quot;status IS NULL and group_id IN (1,2,3)&quot;
  { :age =&gt; 13..18 }
    # =&gt; &quot;age BETWEEN 13 AND 18&quot;
  { 'other_records.id' =&gt; 7 }
    # =&gt; &quot;`other_records`.`id` = 7&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001422-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001422-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1804</span>
1804:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">attrs</span>)
1805:           <span class="ruby-identifier">conditions</span> = <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
1806:             <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>
1807: 
1808:             <span class="ruby-comment cmt"># Extract table name from qualified attribute names.</span>
1809:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'.'</span>)
1810:               <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>, <span class="ruby-value">2</span>)
1811:               <span class="ruby-identifier">table_name</span> = <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_table_name</span>(<span class="ruby-identifier">table_name</span>)
1812:             <span class="ruby-keyword kw">else</span>
1813:               <span class="ruby-identifier">table_name</span> = <span class="ruby-identifier">quoted_table_name</span>
1814:             <span class="ruby-keyword kw">end</span>
1815: 
1816:             <span class="ruby-node">&quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;</span>
1817:           <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">' AND '</span>)
1818: 
1819:           <span class="ruby-identifier">replace_bind_variables</span>(<span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">expand_range_bind_variables</span>(<span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">values</span>))
1820:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001417" class="method-detail">
        <a name="M001417"></a>

        <div class="method-heading">
          <a href="#M001417" class="method-signature">
          <span class="method-name">with_exclusive_scope</span><span class="method-args">(method_scoping = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works like <a href="Base.html#M001416">with_scope</a>, but discards any
nested properties.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001417-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001417-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1700</span>
1700:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_exclusive_scope</span>(<span class="ruby-identifier">method_scoping</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1701:           <span class="ruby-identifier">with_scope</span>(<span class="ruby-identifier">method_scoping</span>, <span class="ruby-identifier">:overwrite</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1702:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001416" class="method-detail">
        <a name="M001416"></a>

        <div class="method-heading">
          <a href="#M001416" class="method-signature">
          <span class="method-name">with_scope</span><span class="method-args">(method_scoping = {}, action = :merge) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Scope parameters to method calls within the block. Takes a <a
href="Base.html#M001457">hash</a> of method_name =&gt; parameters <a
href="Base.html#M001457">hash</a>. method_name may be :<a
href="Base.html#M001376">find</a> or :<a
href="Base.html#M001379">create</a>. :<a href="Base.html#M001376">find</a>
parameters may include the <tt>:conditions</tt>, <tt>:joins</tt>,
<tt>:include</tt>, <tt>:offset</tt>, <tt>:limit</tt>, and
<tt>:readonly</tt> options. :<a href="Base.html#M001379">create</a>
parameters are an <a href="Base.html#M001448">attributes</a> <a
href="Base.html#M001457">hash</a>.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.create_with_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot; }, :create =&gt; { :blog_id =&gt; 1 }) do
        find(1) # =&gt; SELECT * from articles WHERE blog_id = 1 AND id = 1
        a = create(1)
        a.blog_id # =&gt; 1
      end
    end
  end
</pre>
<p>
In nested scopings, all previous parameters are overwritten by the
innermost rule, with the exception of :conditions and :include options in
:<a href="Base.html#M001376">find</a>, which are merged.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.find_with_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot;, :limit =&gt; 1 }, :create =&gt; { :blog_id =&gt; 1 }) do
        with_scope(:find =&gt; { :limit =&gt; 10})
          find(:all) # =&gt; SELECT * from articles WHERE blog_id = 1 LIMIT 10
        end
        with_scope(:find =&gt; { :conditions =&gt; &quot;author_id = 3&quot; })
          find(:all) # =&gt; SELECT * from articles WHERE blog_id = 1 AND author_id = 3 LIMIT 1
        end
      end
    end
  end
</pre>
<p>
You can ignore any previous scopings by using the <tt><a
href="Base.html#M001417">with_exclusive_scope</a></tt> method.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.find_with_exclusive_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot;, :limit =&gt; 1 }) do
        with_exclusive_scope(:find =&gt; { :limit =&gt; 10 })
          find(:all) # =&gt; SELECT * from articles LIMIT 10
        end
      end
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001416-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001416-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1648</span>
1648:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_scope</span>(<span class="ruby-identifier">method_scoping</span> = {}, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">:merge</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1649:           <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">method_scoping</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:method_scoping</span>)
1650: 
1651:           <span class="ruby-comment cmt"># Dup first and second level of hash (method and params).</span>
1652:           <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, (<span class="ruby-identifier">method</span>, <span class="ruby-identifier">params</span>)<span class="ruby-operator">|</span>
1653:             <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = (<span class="ruby-identifier">params</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">params</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">dup</span>
1654:             <span class="ruby-identifier">hash</span>
1655:           <span class="ruby-keyword kw">end</span>
1656: 
1657:           <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">assert_valid_keys</span>([ <span class="ruby-identifier">:find</span>, <span class="ruby-identifier">:create</span> ])
1658: 
1659:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">f</span> = <span class="ruby-identifier">method_scoping</span>[<span class="ruby-identifier">:find</span>]
1660:             <span class="ruby-identifier">f</span>.<span class="ruby-identifier">assert_valid_keys</span>(<span class="ruby-constant">VALID_FIND_OPTIONS</span>)
1661:             <span class="ruby-identifier">set_readonly_option!</span> <span class="ruby-identifier">f</span>
1662:           <span class="ruby-keyword kw">end</span>
1663: 
1664:           <span class="ruby-comment cmt"># Merge scopings</span>
1665:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:merge</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">current_scoped_methods</span>
1666:             <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">current_scoped_methods</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">method_scoping</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, (<span class="ruby-identifier">method</span>, <span class="ruby-identifier">params</span>)<span class="ruby-operator">|</span>
1667:               <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>]
1668:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
1669:                   <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:find</span>
1670:                     (<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>].<span class="ruby-identifier">keys</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">keys</span>).<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
1671:                       <span class="ruby-identifier">merge</span> = <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>] <span class="ruby-comment cmt"># merge if both scopes have the same key</span>
1672:                       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:conditions</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">merge</span>
1673:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = [<span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>], <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>]].<span class="ruby-identifier">collect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">sql</span><span class="ruby-operator">|</span> <span class="ruby-value str">&quot;( %s )&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">sanitize_sql</span>(<span class="ruby-identifier">sql</span>) }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot; AND &quot;</span>)
1674:                       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:include</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">merge</span>
1675:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">merge_includes</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>], <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>]).<span class="ruby-identifier">uniq</span>
1676:                       <span class="ruby-keyword kw">else</span>
1677:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>]
1678:                       <span class="ruby-keyword kw">end</span>
1679:                     <span class="ruby-keyword kw">end</span>
1680:                   <span class="ruby-keyword kw">else</span>
1681:                     <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>])
1682:                   <span class="ruby-keyword kw">end</span>
1683:                 <span class="ruby-keyword kw">else</span>
1684:                   <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = <span class="ruby-identifier">params</span>
1685:               <span class="ruby-keyword kw">end</span>
1686:               <span class="ruby-identifier">hash</span>
1687:             <span class="ruby-keyword kw">end</span>
1688:           <span class="ruby-keyword kw">end</span>
1689: 
1690:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scoped_methods</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">method_scoping</span>
1691: 
1692:           <span class="ruby-keyword kw">begin</span>
1693:             <span class="ruby-keyword kw">yield</span>
1694:           <span class="ruby-keyword kw">ensure</span>
1695:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scoped_methods</span>.<span class="ruby-identifier">pop</span>
1696:           <span class="ruby-keyword kw">end</span>
1697:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001455" class="method-detail">
        <a name="M001455"></a>

        <div class="method-heading">
          <a href="#M001455" class="method-signature">
          <span class="method-name">==</span><span class="method-args">(comparison_object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the <tt>comparison_object</tt> is the same object, or is of
the same type and has the same <a href="Base.html#M001426">id</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001455-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001455-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2187</span>
2187:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">comparison_object</span>)
2188:         <span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">||</span>
2189:           (<span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&amp;&amp;</span>
2190:             <span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span> <span class="ruby-operator">&amp;&amp;</span>
2191:             <span class="ruby-operator">!</span><span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">new_record?</span>)
2192:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001445" class="method-detail">
        <a name="M001445"></a>

        <div class="method-heading">
          <a href="#M001445" class="method-signature">
          <span class="method-name">[]</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the value of the attribute identified by <tt>attr_name</tt> after
it has been typecast (for example, &quot;2004-12-12&quot; in a data column
is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the
protected read_attribute method).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001445-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001445-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2094</span>
2094:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">attr_name</span>)
2095:         <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attr_name</span>)
2096:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001446" class="method-detail">
        <a name="M001446"></a>

        <div class="method-heading">
          <a href="#M001446" class="method-signature">
          <span class="method-name">[]=</span><span class="method-args">(attr_name, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates the attribute identified by <tt>attr_name</tt> with the specified
<tt>value</tt>. (Alias for the protected write_attribute method).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001446-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001446-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2100</span>
2100:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">value</span>)
2101:         <span class="ruby-identifier">write_attribute</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">value</span>)
2102:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001450" class="method-detail">
        <a name="M001450"></a>

        <div class="method-heading">
          <a href="#M001450" class="method-signature">
          <span class="method-name">attribute_for_inspect</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Format <a href="Base.html#M001448">attributes</a> nicely for <a
href="Base.html#M001410">inspect</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001450-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001450-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2152</span>
2152:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_for_inspect</span>(<span class="ruby-identifier">attr_name</span>)
2153:         <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attr_name</span>)
2154: 
2155:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">50</span>
2156:           <span class="ruby-node">&quot;#{value[0..50]}...&quot;</span>.<span class="ruby-identifier">inspect</span>
2157:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Date</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Time</span>)
2158:           <span class="ruby-node">%(&quot;#{value.to_s(:db)}&quot;)</span>
2159:         <span class="ruby-keyword kw">else</span>
2160:           <span class="ruby-identifier">value</span>.<span class="ruby-identifier">inspect</span>
2161:         <span class="ruby-keyword kw">end</span>
2162:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001453" class="method-detail">
        <a name="M001453"></a>

        <div class="method-heading">
          <a href="#M001453" class="method-signature">
          <span class="method-name">attribute_names</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of names for the <a
href="Base.html#M001448">attributes</a> available on this object sorted
alphabetically.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001453-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001453-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2177</span>
2177:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_names</span>
2178:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>
2179:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001451" class="method-detail">
        <a name="M001451"></a>

        <div class="method-heading">
          <a href="#M001451" class="method-signature">
          <span class="method-name">attribute_present?</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the specified <tt>attribute</tt> has been set by the user
or by a database load and is neither nil nor empty? (the latter only
applies to objects that respond to empty?, most notably Strings).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001451-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001451-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2166</span>
2166:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_present?</span>(<span class="ruby-identifier">attribute</span>)
2167:         <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attribute</span>)
2168:         <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">blank?</span>
2169:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001448" class="method-detail">
        <a name="M001448"></a>

        <div class="method-heading">
          <a href="#M001448" class="method-signature">
          <span class="method-name">attributes</span><span class="method-args">(options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001457">hash</a> of all the <a
href="Base.html#M001448">attributes</a> with their names as keys and clones
of their objects as values.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001448-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001448-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2126</span>
2126:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
2127:         <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">clone_attributes</span> <span class="ruby-identifier">:read_attribute</span>
2128: 
2129:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">nil?</span>
2130:           <span class="ruby-identifier">attributes</span>
2131:         <span class="ruby-keyword kw">else</span>
2132:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">except</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:except</span>]
2133:             <span class="ruby-identifier">except</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">except</span>).<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attribute</span><span class="ruby-operator">|</span> <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span> }
2134:             <span class="ruby-identifier">except</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attribute_name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">attribute_name</span>) }
2135:             <span class="ruby-identifier">attributes</span>
2136:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">only</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only</span>]
2137:             <span class="ruby-identifier">only</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">only</span>).<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attribute</span><span class="ruby-operator">|</span> <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span> }
2138:             <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">only</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>) }
2139:             <span class="ruby-identifier">attributes</span>
2140:           <span class="ruby-keyword kw">else</span>
2141:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Options does not specify :except or :only (#{options.keys.inspect})&quot;</span>
2142:           <span class="ruby-keyword kw">end</span>
2143:         <span class="ruby-keyword kw">end</span>
2144:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001447" class="method-detail">
        <a name="M001447"></a>

        <div class="method-heading">
          <a href="#M001447" class="method-signature">
          <span class="method-name">attributes=</span><span class="method-args">(new_attributes, guard_protected_attributes = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Allows you to set all the <a href="Base.html#M001448">attributes</a> at
once by passing in a <a href="Base.html#M001457">hash</a> with keys
matching the attribute names (which again matches the column names).
Sensitive <a href="Base.html#M001448">attributes</a> can be protected from
this form of mass-assignment by using the <tt><a
href="Base.html#M001390">attr_protected</a></tt> macro. Or you can
alternatively specify which <a href="Base.html#M001448">attributes</a>
<b>can</b> be accessed with the <tt><a
href="Base.html#M001391">attr_accessible</a></tt> macro. Then all the <a
href="Base.html#M001448">attributes</a> not included in that won&#8216;t be
allowed to be mass-assigned.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001447-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001447-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2109</span>
2109:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes=</span>(<span class="ruby-identifier">new_attributes</span>, <span class="ruby-identifier">guard_protected_attributes</span> = <span class="ruby-keyword kw">true</span>)
2110:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_attributes</span>.<span class="ruby-identifier">nil?</span>
2111:         <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">new_attributes</span>.<span class="ruby-identifier">dup</span>
2112:         <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">stringify_keys!</span>
2113: 
2114:         <span class="ruby-identifier">multi_parameter_attributes</span> = []
2115:         <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">remove_attributes_protected_from_mass_assignment</span>(<span class="ruby-identifier">attributes</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">guard_protected_attributes</span>
2116: 
2117:         <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
2118:           <span class="ruby-identifier">k</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">&quot;(&quot;</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">multi_parameter_attributes</span> <span class="ruby-operator">&lt;&lt;</span> [ <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span> ] <span class="ruby-operator">:</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">k</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;=&quot;</span>, <span class="ruby-identifier">v</span>)
2119:         <span class="ruby-keyword kw">end</span>
2120: 
2121:         <span class="ruby-identifier">assign_multiparameter_attributes</span>(<span class="ruby-identifier">multi_parameter_attributes</span>)
2122:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001449" class="method-detail">
        <a name="M001449"></a>

        <div class="method-heading">
          <a href="#M001449" class="method-signature">
          <span class="method-name">attributes_before_type_cast</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001457">hash</a> of cloned <a
href="Base.html#M001448">attributes</a> before typecasting and
deserialization.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001449-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001449-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2147</span>
2147:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes_before_type_cast</span>
2148:         <span class="ruby-identifier">clone_attributes</span> <span class="ruby-identifier">:read_attribute_before_type_cast</span>
2149:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001434" class="method-detail">
        <a name="M001434"></a>

        <div class="method-heading">
          <a href="#M001434" class="method-signature">
          <span class="method-name">becomes</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an instance of the specified klass with the <a
href="Base.html#M001448">attributes</a> of the current record. This is
mostly useful in relation to single-table inheritance structures where you
want a subclass to appear as the superclass. This can be used along with
record identification in Action Pack to allow, say, Client &lt; Company to
do something like render :partial =&gt; @client.becomes(Company) to render
that instance using the companies/company partial instead of
clients/client.
</p>
<p>
Note: The <a href="Base.html#M001425">new</a> instance will share a link to
the same <a href="Base.html#M001448">attributes</a> as the original class.
So any change to the <a href="Base.html#M001448">attributes</a> in either
instance will affect the other.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001434-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001434-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2015</span>
2015:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">becomes</span>(<span class="ruby-identifier">klass</span>)
2016:         <span class="ruby-identifier">returning</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">became</span><span class="ruby-operator">|</span>
2017:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@attributes&quot;</span>, <span class="ruby-ivar">@attributes</span>)
2018:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@attributes_cache&quot;</span>, <span class="ruby-ivar">@attributes_cache</span>)
2019:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@new_record&quot;</span>, <span class="ruby-identifier">new_record?</span>)
2020:         <span class="ruby-keyword kw">end</span>
2021:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001433" class="method-detail">
        <a name="M001433"></a>

        <div class="method-heading">
          <a href="#M001433" class="method-signature">
          <span class="method-name">clone</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001433">clone</a> of the record that
hasn&#8216;t been assigned an <a href="Base.html#M001426">id</a> yet and is
treated as a <a href="Base.html#M001425">new</a> record. Note that this is
a &quot;shallow&quot; <a href="Base.html#M001433">clone</a>: it copies the
object&#8216;s <a href="Base.html#M001448">attributes</a> only, not its
associations. The extent of a &quot;deep&quot; <a
href="Base.html#M001433">clone</a> is application-specific and is therefore
left to the application to implement according to its need.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001433-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001433-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2000</span>
2000:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clone</span>
2001:         <span class="ruby-identifier">attrs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes_before_type_cast</span>
2002:         <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>)
2003:         <span class="ruby-identifier">record</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>
2004:         <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">:instance_variable_set</span>, <span class="ruby-value str">'@attributes'</span>, <span class="ruby-identifier">attrs</span>
2005:         <span class="ruby-identifier">record</span>
2006:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001454" class="method-detail">
        <a name="M001454"></a>

        <div class="method-heading">
          <a href="#M001454" class="method-signature">
          <span class="method-name">column_for_attribute</span><span class="method-args">(name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the column object for the named attribute.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001454-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001454-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2182</span>
2182:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">column_for_attribute</span>(<span class="ruby-identifier">name</span>)
2183:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>]
2184:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001466" class="method-detail">
        <a name="M001466"></a>

        <div class="method-heading">
          <a href="#M001466" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Base.html#M001463">connection</a> currently associated
with the class. This can also be used to &quot;borrow&quot; the <a
href="Base.html#M001463">connection</a> to do database work that
isn&#8216;t easily done without going straight to SQL.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001466-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001466-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 173</span>
173:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>
174:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">connection</span>
175:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001440" class="method-detail">
        <a name="M001440"></a>

        <div class="method-heading">
          <a href="#M001440" class="method-signature">
          <span class="method-name">decrement</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Initializes the <tt>attribute</tt> to zero if nil and subtracts one. Only
makes sense for number-based <a href="Base.html#M001448">attributes</a>.
Returns self.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001440-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001440-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2057</span>
2057:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement</span>(<span class="ruby-identifier">attribute</span>)
2058:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
2059:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
2060:         <span class="ruby-keyword kw">self</span>
2061:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001441" class="method-detail">
        <a name="M001441"></a>

        <div class="method-heading">
          <a href="#M001441" class="method-signature">
          <span class="method-name">decrement!</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decrements the <tt>attribute</tt> and saves the record.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001441-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001441-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2064</span>
2064:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement!</span>(<span class="ruby-identifier">attribute</span>)
2065:         <span class="ruby-identifier">decrement</span>(<span class="ruby-identifier">attribute</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2066:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001432" class="method-detail">
        <a name="M001432"></a>

        <div class="method-heading">
          <a href="#M001432" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the record in the database and freezes this instance to reflect
that no changes should be made (since they can&#8216;t be persisted).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001432-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001432-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1983</span>
1983:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>
1984:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">new_record?</span>
1985:           <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value str">&quot;DELETE FROM \#{self.class.quoted_table_name}\nWHERE \#{connection.quote_column_name(self.class.primary_key)} = \#{quoted_id}\n&quot;</span>, <span class="ruby-node">&quot;#{self.class.name} Destroy&quot;</span>
1986:         <span class="ruby-keyword kw">end</span>
1987: 
1988:         <span class="ruby-identifier">freeze</span>
1989:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001456" class="method-detail">
        <a name="M001456"></a>

        <div class="method-heading">
          <a href="#M001456" class="method-signature">
          <span class="method-name">eql?</span><span class="method-args">(comparison_object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delegates to ==
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001456-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001456-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2195</span>
2195:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">comparison_object</span>)
2196:         <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">comparison_object</span>)
2197:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001458" class="method-detail">
        <a name="M001458"></a>

        <div class="method-heading">
          <a href="#M001458" class="method-signature">
          <span class="method-name">freeze</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Freeze the <a href="Base.html#M001448">attributes</a> <a
href="Base.html#M001457">hash</a> such that associations are still
accessible, even on destroyed records.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001458-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001458-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2206</span>
2206:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">freeze</span>
2207:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">freeze</span>; <span class="ruby-keyword kw">self</span>
2208:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001459" class="method-detail">
        <a name="M001459"></a>

        <div class="method-heading">
          <a href="#M001459" class="method-signature">
          <span class="method-name">frozen?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>true</tt> if the <a href="Base.html#M001448">attributes</a> <a
href="Base.html#M001457">hash</a> has been frozen.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001459-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001459-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2211</span>
2211:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">frozen?</span>
2212:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">frozen?</span>
2213:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001452" class="method-detail">
        <a name="M001452"></a>

        <div class="method-heading">
          <a href="#M001452" class="method-signature">
          <span class="method-name">has_attribute?</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the given attribute is in the <a
href="Base.html#M001448">attributes</a> <a
href="Base.html#M001457">hash</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001452-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001452-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2172</span>
2172:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_attribute?</span>(<span class="ruby-identifier">attr_name</span>)
2173:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>)
2174:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001457" class="method-detail">
        <a name="M001457"></a>

        <div class="method-heading">
          <a href="#M001457" class="method-signature">
          <span class="method-name">hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delegates to <a href="Base.html#M001426">id</a> in order to allow two
records of the same type and <a href="Base.html#M001426">id</a> to work
with something like:
</p>
<pre>
  [ Person.find(1), Person.find(2), Person.find(3) ] &amp; [ Person.find(1), Person.find(4) ] # =&gt; [ Person.find(1) ]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001457-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001457-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2201</span>
2201:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
2202:         <span class="ruby-identifier">id</span>.<span class="ruby-identifier">hash</span>
2203:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001426" class="method-detail">
        <a name="M001426"></a>

        <div class="method-heading">
          <a href="#M001426" class="method-signature">
          <span class="method-name">id</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A model instance&#8216;s primary key is always available as model.id
whether you name it the default &#8216;<a
href="Base.html#M001426">id</a>&#8217; or set it to something else.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001426-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001426-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1935</span>
1935:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id</span>
1936:         <span class="ruby-identifier">attr_name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>
1937:         <span class="ruby-identifier">column</span> = <span class="ruby-identifier">column_for_attribute</span>(<span class="ruby-identifier">attr_name</span>)
1938: 
1939:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:define_read_method</span>, <span class="ruby-identifier">:id</span>, <span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">column</span>)
1940:         <span class="ruby-comment cmt"># now that the method exists, call it</span>
1941:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_sym</span>
1942: 
1943:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001428" class="method-detail">
        <a name="M001428"></a>

        <div class="method-heading">
          <a href="#M001428" class="method-signature">
          <span class="method-name">id=</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the primary ID.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001428-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001428-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1960</span>
1960:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id=</span>(<span class="ruby-identifier">value</span>)
1961:         <span class="ruby-identifier">write_attribute</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>, <span class="ruby-identifier">value</span>)
1962:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001438" class="method-detail">
        <a name="M001438"></a>

        <div class="method-heading">
          <a href="#M001438" class="method-signature">
          <span class="method-name">increment</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Initializes the <tt>attribute</tt> to zero if nil and adds one. Only makes
sense for number-based <a href="Base.html#M001448">attributes</a>. Returns
self.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001438-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001438-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2045</span>
2045:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment</span>(<span class="ruby-identifier">attribute</span>)
2046:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
2047:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
2048:         <span class="ruby-keyword kw">self</span>
2049:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001439" class="method-detail">
        <a name="M001439"></a>

        <div class="method-heading">
          <a href="#M001439" class="method-signature">
          <span class="method-name">increment!</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Increments the <tt>attribute</tt> and saves the record.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001439-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001439-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2052</span>
2052:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment!</span>(<span class="ruby-identifier">attribute</span>)
2053:         <span class="ruby-identifier">increment</span>(<span class="ruby-identifier">attribute</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2054:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001462" class="method-detail">
        <a name="M001462"></a>

        <div class="method-heading">
          <a href="#M001462" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the contents of the record as a nicely formatted string.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001462-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001462-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2227</span>
2227:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
2228:         <span class="ruby-identifier">attributes_as_nice_string</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
2229:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_attribute?</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">new_record?</span>
2230:             <span class="ruby-node">&quot;#{name}: #{attribute_for_inspect(name)}&quot;</span>
2231:           <span class="ruby-keyword kw">end</span>
2232:         }.<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;, &quot;</span>)
2233:         <span class="ruby-node">&quot;#&lt;#{self.class} #{attributes_as_nice_string}&gt;&quot;</span>
2234:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001429" class="method-detail">
        <a name="M001429"></a>

        <div class="method-heading">
          <a href="#M001429" class="method-signature">
          <span class="method-name">new_record?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if this object hasn&#8216;t been saved yet &#8212; that is, a
record for the object doesn&#8216;t exist yet.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001429-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001429-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1965</span>
1965:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_record?</span>
1966:         <span class="ruby-ivar">@new_record</span>
1967:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001461" class="method-detail">
        <a name="M001461"></a>

        <div class="method-heading">
          <a href="#M001461" class="method-signature">
          <span class="method-name">readonly!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Marks this record as read only.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001461-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001461-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2222</span>
2222:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly!</span>
2223:         <span class="ruby-ivar">@readonly</span> = <span class="ruby-keyword kw">true</span>
2224:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001460" class="method-detail">
        <a name="M001460"></a>

        <div class="method-heading">
          <a href="#M001460" class="method-signature">
          <span class="method-name">readonly?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>true</tt> if the record is read only. Records loaded through
joins with piggy-back <a href="Base.html#M001448">attributes</a> will be
marked as read only since they cannot be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001460-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001460-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2217</span>
2217:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly?</span>
2218:         <span class="ruby-ivar">@readonly</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
2219:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001444" class="method-detail">
        <a name="M001444"></a>

        <div class="method-heading">
          <a href="#M001444" class="method-signature">
          <span class="method-name">reload</span><span class="method-args">(options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reloads the <a href="Base.html#M001448">attributes</a> of this object from
the database. The optional options argument is passed to <a
href="Base.html#M001376">find</a> when reloading so you may do e.g.
record.reload(:lock =&gt; true) to <a href="Base.html#M001444">reload</a>
the same record with an exclusive row lock.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001444-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001444-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2083</span>
2083:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
2084:         <span class="ruby-identifier">clear_aggregation_cache</span>
2085:         <span class="ruby-identifier">clear_association_cache</span>
2086:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">update</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">find</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">'@attributes'</span>))
2087:         <span class="ruby-ivar">@attributes_cache</span> = {}
2088:         <span class="ruby-keyword kw">self</span>
2089:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001430" class="method-detail">
        <a name="M001430"></a>

        <div class="method-heading">
          <a href="#M001430" class="method-signature">
          <span class="method-name">save</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <ul>
<li>No record exists: Creates a <a href="Base.html#M001425">new</a> record with
values matching those of the object <a
href="Base.html#M001448">attributes</a>.

</li>
<li>A record does exist: Updates the record with values matching those of the
object <a href="Base.html#M001448">attributes</a>.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001430-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001430-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1971</span>
1971:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>
1972:         <span class="ruby-identifier">create_or_update</span>
1973:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001431" class="method-detail">
        <a name="M001431"></a>

        <div class="method-heading">
          <a href="#M001431" class="method-signature">
          <span class="method-name">save!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attempts to <a href="Base.html#M001430">save</a> the record, but instead of
just returning false if it couldn&#8216;t happen, it raises a <a
href="RecordNotSaved.html">RecordNotSaved</a> exception
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001431-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001431-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1977</span>
1977:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save!</span>
1978:         <span class="ruby-identifier">create_or_update</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RecordNotSaved</span>)
1979:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001427" class="method-detail">
        <a name="M001427"></a>

        <div class="method-heading">
          <a href="#M001427" class="method-signature">
          <span class="method-name">to_param</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Enables Active Record objects to be used as URL parameters in Action Pack
automatically.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001427-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001427-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1946</span>
1946:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_param</span>
1947:         <span class="ruby-comment cmt"># We can't use alias_method here, because method 'id' optimizes itself on the fly.</span>
1948:         (<span class="ruby-identifier">id</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># Be sure to stringify the id for routes</span>
1949:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001442" class="method-detail">
        <a name="M001442"></a>

        <div class="method-heading">
          <a href="#M001442" class="method-signature">
          <span class="method-name">toggle</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Turns an <tt>attribute</tt> that&#8216;s currently true into false and vice
versa. Returns self.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001442-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001442-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2069</span>
2069:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">toggle</span>(<span class="ruby-identifier">attribute</span>)
2070:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] = <span class="ruby-operator">!</span><span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{attribute}?&quot;</span>)
2071:         <span class="ruby-keyword kw">self</span>
2072:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001443" class="method-detail">
        <a name="M001443"></a>

        <div class="method-heading">
          <a href="#M001443" class="method-signature">
          <span class="method-name">toggle!</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Toggles the <tt>attribute</tt> and saves the record.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001443-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001443-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2075</span>
2075:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">toggle!</span>(<span class="ruby-identifier">attribute</span>)
2076:         <span class="ruby-identifier">toggle</span>(<span class="ruby-identifier">attribute</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2077:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001435" class="method-detail">
        <a name="M001435"></a>

        <div class="method-heading">
          <a href="#M001435" class="method-signature">
          <span class="method-name">update_attribute</span><span class="method-args">(name, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates a single attribute and saves the record. This is especially useful
for boolean flags on existing records. Note: This method is overwritten by
the Validation module that&#8216;ll make sure that updates made with this
method aren&#8216;t subjected to validation checks. Hence, <a
href="Base.html#M001448">attributes</a> can be updated even if the full
object isn&#8216;t valid.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001435-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001435-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2026</span>
2026:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
2027:         <span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'='</span>, <span class="ruby-identifier">value</span>)
2028:         <span class="ruby-identifier">save</span>
2029:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001436" class="method-detail">
        <a name="M001436"></a>

        <div class="method-heading">
          <a href="#M001436" class="method-signature">
          <span class="method-name">update_attributes</span><span class="method-args">(attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates all the <a href="Base.html#M001448">attributes</a> from the
passed-in Hash and saves the record. If the object is invalid, the saving
will fail and false will be returned.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001436-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001436-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2033</span>
2033:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">attributes</span>)
2034:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span>
2035:         <span class="ruby-identifier">save</span>
2036:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001437" class="method-detail">
        <a name="M001437"></a>

        <div class="method-heading">
          <a href="#M001437" class="method-signature">
          <span class="method-name">update_attributes!</span><span class="method-args">(attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates an object just like <a
href="Base.html#M001436">Base.update_attributes</a> but calls <a
href="Base.html#M001431">save!</a> instead of <a
href="Base.html#M001430">save</a> so an exception is raised if the record
is invalid.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001437-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001437-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2039</span>
2039:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attributes!</span>(<span class="ruby-identifier">attributes</span>)
2040:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span>
2041:         <span class="ruby-identifier">save!</span>
2042:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>